[Image-SIG] uchar pointer to image

Fredrik Lundh fredrik at pythonware.com
Thu Jun 2 10:00:18 CEST 2005

"W. John" <neojohn75 at yahoo.com> wrote:

>  This is a newbie question about PIL and Python. If I
> have a shared character array (buffer) that is
> allocated in a C++ class using "mmap".  A function
> called 'Capture' returns a pointer to that shared
> area, and after a wrapper for Python I'm doing
> something like this:
>   >data=mycam.Capture()
>   >print data
>   _0810cdbe_p_uchar
> How can I convert "data" (the uchar pointer) to an PIL
> image?

Python doesn't support "uchar pointers", so it's impossible to answer
your question unless unless you tell us what the data object really is.

  Do I need to use the "fromstring" fuction?  I
> tried something like this but is not working.
>   >image=Image.new("L",(640,480))
>   >image.fromstring(data)

define "not working".  does it give you a traceback, a segmentation
violation, or garbled image data?

if data is a string or buffer-compatible object, that should work (see
Douglas' reply for more details).  if it doesn't work, chances are that
data is something else.  if so, you have to figure out how to turn the
contents of data into a Python string.


More information about the Image-SIG mailing list