[vtkusers] Generate in-memory JPEG images in Python

David Gobbi david.gobbi at gmail.com
Tue Aug 30 11:53:58 EDT 2011


On Tue, Aug 30, 2011 at 9:49 AM, Shead, Timothy <tshead at sandia.gov> wrote:
>
> On Aug 29, 2011, at 9:18 PM, Shead, Timothy wrote:
>
>> Gang:
>>
>> I'm experimenting with generating an offscreen JPEG image on a web-server using VTK and Python, but I'm hung-up on how to convert the vtkUnsignedCharArray returned by vtkJPEGWriter::GetResult() into a Python string or buffer.  Any thoughts?  I see that it's easy to create a numpy array that points to the same memory, maybe there's something I could do with it?
>
> OK, answering my own question - you can convert vtkUnsignedCharArray to a numpy.ndarray using vtk.util.numpy_support.vtk_to_numpy(), then use the numpy array's tostring() method.  Feedback welcome if there's anything more direct.

Tim, no conversion should be necessary at all.  The vtkDataArray
classes support the python buffer protocol directly.  Just pass the
vtkDataArray to any python method that takes a buffer object, and it
should just work.

 - David



More information about the vtkusers mailing list