[vtkusers] Inverse of vtkQImageToImageSource?
Julien Finet
julien.finet at kitware.com
Fri Sep 16 22:21:43 EDT 2011
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.
On Fri, Sep 16, 2011 at 3:24 PM, David Doria <daviddoria at gmail.com> wrote:
> This class convers a QImage to a vtkImageData. Has anyone see or written a
> class to do the inverse - convert a vtkImageData to a QImage?
>
> Thanks,
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110916/197faee4/attachment.htm>
More information about the vtkusers
mailing list