[Image-SIG] How to get the PIL object from an image buffer createdin C++?
Fredrik Lundh
fredrik at pythonware.com
Fri Sep 30 11:47:21 CEST 2005
"john taylor" wrote:
> 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);
> }
you're passing in the address of the pointer, not the address of the
buffer. try changing this to:
return Py_BuildValue("s#", ImageBuffer, 640*480);
or, better:
return PyString_FromStringAndSize(ImageBuffer, 640*480);
(your malloc/pystring/fromstring approach does a of extra copying, but
I suppose you can start worrying about that only if you find that it's not
fast enough...)
</F>
More information about the Image-SIG
mailing list