[vtkusers] Save screenshot of a rendered chart

kostadus kostadus at yahoo.com
Tue Jan 19 16:22:56 EST 2016


Dear vtk team and users,
I am using vtk to plot some histograms in a chart and i want to save this
chart in a png file. I tried to add the png writer available in the example
in the web but however the png file i store is corrupted. Any ideas to come
around this issue? A snipshet of my code is pasted below.



 // Set up the view
  vtkSmartPointer<vtkContextView> view =
vtkSmartPointer<vtkContextView>::New();
  view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  view->GetRenderWindow()->SetSize(800,600);
  view->GetRenderWindow()->SetAlphaBitPlanes(1);
  view->GetScene()->AddItem(chart);
  chart->SetShowLegend(true);
  chart->SetTitle("Dose Volume Histogram");
  chart->GetAxis(vtkAxis::BOTTOM)->SetTitle("Dose Gy ");
  chart->GetAxis(vtkAxis::LEFT)->SetTitle("Volume % ");
  // Start interactor
  
    // Screenshot  
  vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
vtkSmartPointer<vtkWindowToImageFilter>::New();
  windowToImageFilter->SetInput(view->GetRenderWindow());
  windowToImageFilter->SetMagnification(1); //set the resolution of the
output image (3 times the current resolution of vtk render window)
  windowToImageFilter->SetInputBufferTypeToRGB(); //also record the alpha
(transparency) channel
  windowToImageFilter->ReadFrontBufferOff(); // read from the back buffer
  windowToImageFilter->Update();
 
  vtkSmartPointer<vtkPNGWriter> writer =
vtkSmartPointer<vtkPNGWriter>::New();
  writer->SetFileName("/home/mood/screenshot.png");
  writer->SetInputConnection(windowToImageFilter->GetOutputPort());
  writer->Write();
  
  view->GetInteractor()->Initialize();
  view->GetInteractor()->Start();


Thank you in advance,
Konstantinos Mountris



--
View this message in context: http://vtk.1045678.n5.nabble.com/Save-screenshot-of-a-rendered-chart-tp5736031.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list