[Image-SIG] Float PIL image to bitmap

Cliff Wells logiplexsoftware@earthlink.net
Thu, 15 Nov 2001 13:05:00 -0800


On Thursday 15 November 2001 11:50, John Hunter wrote:
> I have a grayscale PIL image created from a file of 16 bit floats:
>
>   data = open(inFile, 'rb').read(131072)
>   im = Image.fromstring( "F", (256,256), data, \
>                        "raw", "F;16B", 0, 1)
>
> I would like to use this in wxPython as a bitmap.  Currently I am
> using the wxImage method ConvertToBitmap after first converting the
> PIL image to a wxImage using Cliff Wells' PILToWx (see below)
>
>   bmp = PILToWX( pil ).ConvertToBitmap()
>
> but this isn't very efficient.  Is there a way to get the bitmap
> directly from the float PIL image without having to go through the
> intermediary wxImage?  I tried

I do the same thing, although efficiency hasn't been a problem in my 
application (it only needs this conversion occasionally, and it does seem 
fairly fast), but I would also be interested in seeing a more efficient 
method.  I've been stumped on this because of the wildly different methods 
available between wxImage and wxBitmap.  I'm not sure why they are so 
different, but I constantly find it necessary to convert back and forth 
between the two in order to perform some operation that one or the other 
lacks (in this case, wxBitmap lacks a SetData method).

BTW, just to properly distribute credit, the basic code for PILToWX 
originally came from PIDDLE.

Regards,

-- 
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308