2014-02-06 64 views
1

我是新來的pygame的,我試圖創建從RGB565緩衝的表面上,這是我到目前爲止有: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

回答

1

我應該用column_stack獲得r g b r g b...

arr = np.column_stack((r,g,b)).flat[0:]