[Image-SIG] How to get the PIL object from an image buffer created in C++?

john taylor x12345jp at yahoo.com.hk
Fri Sep 30 11:07:42 CEST 2005


Hi all,

I've produced a DLL from my C++ program, which gets an
image from external hardware and saves to a buffer.
How can I get the image data from the DLL in Python?

The C functions are somehow implemented as follows:

static char *ImageBuffer = NULL;

int WriteImageBuffer(void)
{
    // acquire an image and write to the buffer
    AcquireImg(ImageBuffer, params);
}

PyObject* GetImage(void)
{
    return Py_BuildValue("s#", &ImageBuffer, 640*480);
}

In Python I got (I am using ctypes for calling DLL's),

(... some code here to load the library)

>>> @cdecl(c_char_p, dll, [])
... def GetImage():
... 	return GetImage._api_()
... 
>>> data = GetImage()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<interactive input>", line 3, in GetImage
WindowsError: exception: access violation reading
0x0181D000

If i could get the PIL string here, I'd like to use
image = Image.fromstring("L", (640, 480), data)
to have a PIL Image object.

Any body can help?  Thanks a lot in advance!!

John


More information about the Image-SIG mailing list