Function GetData() in wxImage

Mike C. Fletcher mcfletch at rogers.com
Wed Oct 9 10:59:33 EDT 2002


"wxImage to DATA --  myWxImage.GetData()  returning a string in width * 
height * 3 format"

i.e. the data is given back as a string (a python string) of width * 
height * RGB.  Use Image.fromstring to create a PIL image anywhere you 
see the "DATA format" (i.e. raw data) available (DATA == string of 
width*height*RGB bytes in a string).  Image.open takes a file-like 
object, not a string, and it's generally only used when you have the 
data encoded (i.e. not as raw data).


Feel free to improve the Wiki docs to clarify or point out whatever is 
causing confusion (that's what wikis are for).


HTH,
Mike

Anand wrote:

>Hi Mike
>
> How do I create a PIL Image instance from a wxImage instance.
>In your code you have done the reverse, ie creating a wxImage instance
>from a PIL image.
>
> img = Image.open(file,'r')
> self.wxImg.SetData( img.convert( "RGB").tostring() ) 
>
> How do I use the GetData() on wxImage() to create a PIL image.
> I tried,
>
>  img = Image.open(str(self.wxImg.GetData()))
> But python runtime complains that the data is NULL padded which is correct.
> since the chunk is binary.
>
> Do I need to call 'encode()' on the chunk to use the above ?
> If so what encoding?
>
>Thanks
>
>Anand
>
>"Mike C. Fletcher" <mcfletch at rogers.com> wrote in message news:<mailman.1034004310.4308.python-list at python.org>...
>  
>
>>http://wiki.wxpython.org/index.cgi/WorkingWithImages
>>
>>BTW: It's generally more efficient to use the wxPython users mailing 
>>list for these kinds of questions.
>>
>>Enjoy,
>>Mike
>>
>>Anand wrote:
>>
>>    
>>
>>>Hi
>>>
>>>I am writing an image viewer in wxPython using the wxImage class.
>>>I want to manipulate the image data for effects. I tried to use the
>>>GetData() method of the wxImage class which returns a const char *(wxWindows
>>>documentation). 
>>>
>>>How do I manipulate this object. Is it a python object or a C unsigned char *
>>>stream ? Can i apply std 'C' calls on it or do I need to use methods of
>>>python ?
>>>
>>>Concerned code...
>>>
>>>def myfunc:
>>>
>>>  ...
>>>  self.img = wxImage(fileName)
>>>  chunk = self.img.GetData()  # What is this chunk ?
>>>  pass
>>>
>>>
>>>Thanks
>>>
>>>Anand
>>> 
>>>
>>>      
>>>

-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/







More information about the Python-list mailing list