RGB565的pygame曲面

2024-05-19 19:48:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我是pygame的新手,我正在尝试从RGB565缓冲区创建一个曲面,这是我目前所拥有的:

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')

它工作,除了图像是平铺的,你知道我做错了什么吗?你知道吗

enter image description here


Tags: todefnprgbsurfacepygamebuff缓冲区