简体   繁体   中英

pygame Surface from RGB565

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM