【问题标题】:from binary data to wxbitmap从二进制数据到 wxbitmap
【发布时间】:2012-01-29 07:08:32
【问题描述】:

我有一个将灰度图像存储为一系列 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

【问题讨论】:

    标签: python image binary wxpython


    【解决方案1】:

    您可以直接从 numpy 数组中获取 wxBitmap。
    This is an example from wxPyWiki:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 2016-01-06
      相关资源
      最近更新 更多