I have a piece of code that works using
my_surface = pygame.image.load('some_image.png')
This returns a pygame surface. I'd like to use the same code everywhere else but instead pass in a numpy array. (Actually, I'm going to have an if statement that determines whether we have an array or a path to an image. In either case the function has to return the same type of object, a pygame surface. It already works using the above code. Now I have to add a second way of generating the same object if the script is being used differently.) I have tried using
my_surface = pygame.pixelcopy.make_surface(my_array)
but the problem is that this function requires an INTEGER array. My array is a float32. I can force it through by passing the array like so
(my_array*10000).astype(int)
But when I display it later it looks like garbage (imagine my surprise). So my question is, how do we create a pygame surface elegantly out of a numpy array of floats?