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

Mike Taverne mtaverne at engits.com
Mon Sep 14 11:48:18 EDT 2009


I think I know why it doesn't work correctly.
The problem is that when the widget is not completely visible (The
QVTWidget is in a scrollbox in my case), it seems to take a screenshot
of a box the size of the widget, thereby also saving part of what's
outside the main window.

I tried another method which also fails if the QVTKWidget isn't
completely visible:
================
    vtkWindowToImageFilter* filter = vtkWindowToImageFilter::New();
    filter->SetInput(getRenderWindow());
    filter->Modified();
    vtkPNGWriter* writer = vtkPNGWriter::New();
    writer->SetInput(filter->GetOutput());
    writer->SetFileName(qPrintable(filename));
    writer->Write();
    writer->Delete();
================

Is there an easy way to open a new window showing the same contents as
the QVTKWidget, save it as an image and then close it?
Otherwise, I'll probably have to rework my GUI so that the whole
QVTKWidget is always visible, which I would like to avoid.

> You should use the normal methods for capturing images, not the cachedImage in 
> QVTKWidget.  Why that normal method doesn't work for you on Windows, I'm not 
> sure.
>
> Clint
>
> On Monday 14 September 2009 05:01:59 am Mike Taverne wrote:
>   
>> Ok, now I use the following:
>> ==========
>> vtkPNGWriter* writer = vtkPNGWriter::New();
>> writer->SetInput(this->cachedImage());
>> writer->SetFileName(qPrintable(filename));
>> writer->Write();
>>
>> writer->Delete();
>> ==========
>>
>>
>> But then a part of my screen is saved along with the image, i.e. it acts
>> like a screenshot box, but not correctly centered on the widget. :(
>>
>> _______________________________________________
>> 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
>>     
>
>   




More information about the vtkusers mailing list