Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from binary data to wxbitmap
  2. imagearray=numpy.fromfile(file=self.f, dtype=numpy.uint8, count=npixels).reshape(Height, Width)[::-1]
  3. pilimage = Image.fromarray(imagearray)
  4. rgb= pilimage.convert('RGB')
  5. rgbdata = rgb.tostring()
  6. WxBitmap = wx.EmptyBitmap(Width,Height)            
  7. WxBitmap.CopyFromBuffer(rgbdata)
  8. output=WxBitmap
  9.        
  10. import wx, numpy
  11.  
  12. def GetBitmap( self, width=32, height=32, colour = (0,0,0) ):
  13.         array = numpy.zeros( (height, width, 3),'uint8')
  14.         array[:,:,] = colour
  15.         image = wx.EmptyImage(width,height)
  16.         image.SetData( array.tostring())
  17.         wxBitmap = image.ConvertToBitmap()       # OR:  wx.BitmapFromImage(image)
  18.         return wxBitmap