def save_graypixelmap(self): string = glReadPixels(0,0,self.GetSize().x,self.GetSize().y,GL_LUMINANCE,GL_FLOAT) size = list(self.GetClientSizeTuple()) a = fromstring(string,Float32) # convert pixels to array print a.shape, size size[0],size[1] = size[1],size[0] # swap x,y dimensions for proper unraveling carray = reshape(a,size)*255 # must be a luminance map print carray.shape, type(carray), carray.typecode(), min(ravel(carray)), max(ravel(carray)) im.ashow(carray[::-1,:])
def save_colorpixelmap(self): string = glReadPixels(0,0,self.GetSize().x,self.GetSize().y,GL_RGB,GL_UNSIGNED_BYTE) size = list(self.GetClientSizeTuple()) a = fromstring(string,Int8) # convert pixels to array print a.shape, size size[0],size[1] = size[1],size[0] # swap x,y dimensions for proper unraveling r = a[0::3]+0 g = a[1::3]+0 b = a[2::3]+0 r.shape = size g.shape = size b.shape = size carray = array([r[::-1,:],g[::-1,:],b[::-1,:]]) # up-down flip the image print carray.shape, type(carray), carray.typecode(), min(ravel(carray)), max(ravel(carray)) im.ashow(carray)