Python 从二进制数据到wxbitmap

Python 从二进制数据到wxbitmap,python,image,binary,wxpython,Python,Image,Binary,Wxpython,我有一个设备,它将灰度图像存储为一系列8位无符号整数值。我想编写一个python程序,从文件中读取这些图像,并使用wxBitmap显示它们。我有一个可以工作的代码,但由于格式之间的大量转换,它似乎效率低下 任何关于更快代码的建议都将受到高度赞赏 我当前的代码: imagearray=numpy.fromfile(file=self.f, dtype=numpy.uint8, count=npixels).reshape(Height, Width)[::-1] pilimage = Image.

我有一个设备,它将灰度图像存储为一系列8位无符号整数值。我想编写一个python程序,从文件中读取这些图像,并使用wxBitmap显示它们。我有一个可以工作的代码,但由于格式之间的大量转换,它似乎效率低下

任何关于更快代码的建议都将受到高度赞赏

我当前的代码:

imagearray=numpy.fromfile(file=self.f, dtype=numpy.uint8, count=npixels).reshape(Height, Width)[::-1]
pilimage = Image.fromarray(imagearray)
rgb= pilimage.convert('RGB')
rgbdata = rgb.tostring()
WxBitmap = wx.EmptyBitmap(Width,Height)            
WxBitmap.CopyFromBuffer(rgbdata)
output=WxBitmap

您可以直接从numpy数组获取wxBitmap。
:

import wx, numpy

def GetBitmap( self, width=32, height=32, colour = (0,0,0) ):
        array = numpy.zeros( (height, width, 3),'uint8')
        array[:,:,] = colour
        image = wx.EmptyImage(width,height)
        image.SetData( array.tostring())
        wxBitmap = image.ConvertToBitmap()       # OR:  wx.BitmapFromImage(image)
        return wxBitmap