I'm not sure I fully understood this question. As far as I know, pygame surfaces are in RGBA (more precisely, BGRA) adjacent arrays if you start pygame and such surfaces (note the β32β in each line):
# display surface DISP = pygame.display.set_mode((window_w, window_h), 0, 32)
I would also recommend using 32 bits if possible, rather than 24 bits, because 24-bit surfaces are difficult to interact with arrays (I use numpy to store and process image data).
For example, a 24-bit surface should have a number of pixels divisible by 4, if I'm not mistaken.
Like I said, I'm not sure what your last task is, but here's how I do it. For instance. load the image using openCV lib and convert it to a BGRA array:
# BGR 3d numpy array array (shape = h, w, 3) with image data img = cv2.imread(filename) # BGRA 3d numpy array (shape = h, w, 4) img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
Then this function copies all the data in the array to the surface, you just need to be sure that they have the same pixel size:
But it may be that you wanted to do something else.
source share