[vtkusers] Inverse of vtkQImageToImageSource?

David Doria daviddoria at gmail.com
Sun Sep 18 17:46:33 EDT 2011


On Fri, Sep 16, 2011 at 10:21 PM, Julien Finet <julien.finet at kitware.com>wrote:

> Hi David,
>
> The following snippet should do what you need:
>
>     vtkImageData* cachedImage = ...;
>     int width = cachedImage->GetDimensions()[0];
>     int height = cachedImage->GetDimensions()[1];
>     QImage qImage(width, height, QImage::Format_RGB32);
>     QRgb* rgbPtr = reinterpret_cast<QRgb*>(qImage.bits());
>     unsigned char* colorsPtr = reinterpret_cast<unsigned
> char*>(cachedImage->GetScalarPointer());
>     for(int i = 0; i < width * height; ++i)
>       {
>       *(rgbPtr++) = QColor(colorsPtr[0], colorsPtr[1], colorsPtr[2]).rgb();
>       colorsPtr +=  3;
>       }
>
> Regards,
> Julien.
>

Thanks Julien. Here is a complete example for future readers:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/ImageDataToQImage

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110918/f495d032/attachment.htm>


More information about the vtkusers mailing list