[vtkusers] How can I save the contents of a QVTKWidget as an image?

Mike Taverne mtaverne at engits.com
Mon Sep 14 04:38:45 EDT 2009


Hi,

How can I save the contents of a QVTKWidget as an image?
Currently I use the following code:
==========
    vtkRenderLargeImage* renderLarge = vtkRenderLargeImage::New();
    renderLarge->SetInput(getRenderer());
 
    vtkPNGWriter* writer = vtkPNGWriter::New();
    writer->SetInputConnection(renderLarge->GetOutputPort());
    writer->SetFileName(qPrintable(filename));
    writer->Write();
 
    writer->Delete();
    renderLarge->Delete();
==========

Under GNU/Linux, it works well, but not under Windows, where I get
either a completely black image or an image with black bars over it.

I noticed there's a QVTKWidget::cachedImage() function returning a
vtkImageData.

But I can't figure out how to use it.
In VTK 4.2, there was a vtkImageWriter::SetInput(vtkImageData *input)
function, but it is not available anymore in the latest VTK version.

All function allowing passing a vtkImageData seem to be protected now:
AllocateOutputData(vtkImageData *out, int *uExtent)   
vtkImageAlgorithm     [protected, virtual]
CopyAttributeData(vtkImageData *in, vtkImageData *out,
vtkInformationVector **inputVector)    vtkImageAlgorithm     [protected,
virtual]
RecursiveWrite(int dim, vtkImageData *region, ofstream *file)   
vtkImageWriter     [protected, virtual]
RecursiveWrite(int dim, vtkImageData *cache, vtkImageData *data,
ofstream *file)    vtkImageWriter    [protected, virtual]
WriteFile(ofstream *file, vtkImageData *data, int extent[6])   
vtkImageWriter     [protected, virtual]
WriteFileHeader(ofstream *, vtkImageData *)    vtkImageWriter   
 [inline, protected, virtual]
WriteFileTrailer(ofstream *, vtkImageData *)    vtkImageWriter   
[inline, protected, virtual]




More information about the vtkusers mailing list