[vtkusers] Generate in-memory JPEG images in Python

Shead, Timothy tshead at sandia.gov
Tue Aug 30 11:49:20 EDT 2011

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.


Timothy M. Shead
Sandia National Laboratories
1461, Scalable Analysis and Visualization

More information about the vtkusers mailing list