[vtkusers] How to achieve the screen shot with VTK
Vladimir Dudnik
vladimir.dudnik at gmail.com
Mon Apr 15 04:09:11 EDT 2013
Hi,
to capture the content of vtkRenderWindow you can use vtkWindowToImageFilter
function and then to store this to file you may call
vtkBMPWriter/vtkJPEGWriter/vtkPNGWriter functions.
Below is an example of function which capture contnet of render window and
stores it to image file
void 3DView::onWindowScreenshot(void)
{
FileSaveDialog dlg;
dlg.Init(".");
if(QDialog::Accepted == dlg.exec())
{
QString saveFileName = dlg.selectedFiles().last();
QFileInfo fi(saveFileName);
vtkWindowToImageFilter* f = vtkWindowToImageFilter::New();
f->Modified();
f->SetInput(m_qvtkWidget->GetRenderWindow());
f->SetInputBufferTypeToRGBA();
f->Update();
vtkImageData* data = f->GetOutput();
if("png" == fi.suffix())
{
vtkPNGWriter* w = vtkPNGWriter::New();
w->SetFileName(saveFileName.toAscii());
w->SetInput(data);
w->Write();
w->Delete();
}
if("bmp" == fi.suffix())
{
vtkBMPWriter* w = vtkBMPWriter::New();
w->SetFileName(saveFileName.toAscii());
w->SetInput(data);
w->Write();
w->Delete();
}
if("jpg" == fi.suffix())
{
vtkJPEGWriter* w = vtkJPEGWriter::New();
w->SetFileName(saveFileName.toAscii());
w->SetInput(data);
w->Write();
w->Delete();
}
f->Delete();
}
return;
} // onWindowScreenshot()
Here, dialog provides user choosen name and format of file to store. The
content of render window is taken from m_qvtkWidget (which is class variable
of QVTKWidget type). The example is from Qt based application which renders
3D in VTK window.
Hope this helps.
Regards,
Vladimir
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-achieve-the-screen-shot-with-VTK-tp5720048p5720049.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list