任何人都知道我为什么用pygame的
get_buffer
[8, 16, 32, 0]
. 我是做错了什么,还是pygame存储像素数据的方式有问题?
>>> import pygame
>>> import pygame.gfxdraw
>>> import numpy as np
>>> background_colour = (1, 1, 1)
>>> width, height = (256, 256)
>>> screen = pygame.Surface((width, height))
>>> pygame.draw.rect(screen, (8, 16, 32), (0, 0, 100, 100), 0)
<rect(0, 0, 100, 100)>
>>> s = screen.get_buffer()
>>> x = np.fromstring(s.raw, dtype='b').reshape(height, width, 4)
>>> x[0, 0]
array([32, 16, 8, 0], dtype=int8)
我试过了,但是我没有用R值:
>>> y = x[:, :, 3:0:-1]
>>> y[0, 0]
array([ 0, 8, 16], dtype=int8)
np.flip
).