I'm using the SWIG array_class
macro defined in carrays.i to create an unsigned char buffer which can be sent to the c++-side of my project, which handles picture taking. This works fine – the buffer is filled width data after the camera has triggered, and I can dereference the buffer using [] from python to see what it holds. I now want to create a PIL image from that buffer, using Image.frombuffer
:
Image.frombuffer(mode, size, data) => image
(New in PIL 1.1.4). Creates an image memory from pixel data in a string or buffer object, using the standard "raw" decoder.
but I get an error message telling me that the SWIG object I supply is not a python buffer:
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1853, in frombuffer
core.map_buffer(data, size, decoder_name, None, 0, args)
TypeError: expected string or buffer
How can I make this proxy of a SWIG Object compatible with the type of buffer that Image.frombuffer
expects?