When I load png files with pygame.image.load and then get data with pygame.surfarray.pixels2d, I get sometimes color data in ABGR format, and sometimes in RGBA, forcing me to a conversion if copy data from one type to another.
Problem is that I can't foresee if data will be ABGR or RGBA, and I comment or uncomment the conversion when I'm working on another file.
Is there a way to know data type from pygame ?
51 Answer
The pygame.surfarray module provides functions for separately referencing color channels and alpha channels of a pygame.Surface object in an array. Use these functions instead of pygame.surfarray.pixels2d():
Reference pixels into a 3d array
pygame.surfarray.pixels_alpha():
Reference pixel alphas into a 2d array