I'm new to pygame and I'm trying to create a Surface from an RGB565 buffer, this is what I have so far:
def rgb_to_surface(buff):
arr = np.fromstring(buff, dtype=np.uint16).newbyteorder('S')
r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8)
g = (((arr & 0x07E0) >>5) *255.0/63.0).astype(np.uint8)
b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8)
arr = np.concatenate((r,g,b))
return pygame.image.frombuffer(arr, (160, 120), 'RGB')
It works, except that the image is tiled, any idea what I'm doing wrong ?
我应该用column_stack
得到rgbrg b...
arr = np.column_stack((r,g,b)).flat[0:]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.