<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1412789331455_4496">Hello everyone.</div><div id="yui_3_16_0_1_1412789331455_4512"><br></div><div dir="ltr" id="yui_3_16_0_1_1412789331455_4495">This is my first time with VTK and first time I am posting to this list. <br></div><div id="yui_3_16_0_1_1412789331455_4511" dir="ltr">Does anyone have an idea why this code produces black image as a screenshot (attached). I installed vtk 6.1 on Ubuntu 14.04 (on virtual machine). This is just the example I found on <a id="yui_3_16_0_1_1412789331455_4518" href="http://www.cmake.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot">http://www.cmake.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot</a> for saving a screenshot of the render window. I looked around during 2 days but I haven't find a solution.<br></div><div id="yui_3_16_0_1_1412789331455_4511"> <br></div><div dir="ltr" id="yui_3_16_0_1_1412789331455_4707">Thanks a lot.<br></div><br style="" class="">#include <vtkPolyDataMapper.h><br style="" class="">#include <vtkActor.h><br style="" class="">#include <vtkSmartPointer.h><br style="" class="">#include <vtkRenderWindow.h><br style="" class="">#include <vtkRenderer.h><br style="" class="">#include <vtkRenderWindowInteractor.h><br style="" class="">#include <vtkPolyData.h><br style="" class="">#include <vtkSphereSource.h><br style="" class="">#include <vtkWindowToImageFilter.h><br style="" class="">#include <vtkPNGWriter.h><br style="" class=""> <br style="" class=""><br style="" class=""><br style="" class="">int main(int, char *[])<br style="" class="">{<br style="" class=""> vtkSmartPointer<vtkSphereSource> sphereSource = <br style="" class=""> vtkSmartPointer<vtkSphereSource>::New();<br style="" class=""> sphereSource->SetCenter(0.0, 0.0, 0.0);<br style="" class=""> sphereSource->SetRadius(5.0);<br style="" class=""> sphereSource->Update();<br style="" class=""> <br style="" class=""> // Visualize<br style="" class=""> vtkSmartPointer<vtkPolyDataMapper> mapper = <br style="" class=""> vtkSmartPointer<vtkPolyDataMapper>::New();<br style="" class=""> mapper->SetInputConnection(sphereSource->GetOutputPort());<br style="" class=""> <br style="" class=""> vtkSmartPointer<vtkActor> actor = <br style="" class=""> vtkSmartPointer<vtkActor>::New();<br style="" class=""> actor->SetMapper(mapper);<br style="" class=""> <br style="" class=""> vtkSmartPointer<vtkRenderer> renderer = <br style="" class=""> vtkSmartPointer<vtkRenderer>::New();<br style="" class=""> vtkSmartPointer<vtkRenderWindow> renderWindow = <br style="" class=""> vtkSmartPointer<vtkRenderWindow>::New();<br style="" class=""> renderWindow->AddRenderer(renderer);<br style="" class=""> renderWindow->SetAlphaBitPlanes(1); //enable usage of alpha channel<br style="" class=""> <br style="" class=""> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = <br style="" class=""> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br style="" class=""> renderWindowInteractor->SetRenderWindow(renderWindow);<br style="" class=""> <br style="" class=""> renderer->AddActor(actor);<br style="" class=""> renderer->SetBackground(1,1,1); // Background color white<br style="" class=""> <br style="" class=""> renderWindow->Render();<br style="" class=""> <br style="" class=""> // Screenshot <br style="" class=""> vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = <br style="" class=""> vtkSmartPointer<vtkWindowToImageFilter>::New();<br style="" class=""> windowToImageFilter->SetInput(renderWindow);<br style="" class=""> windowToImageFilter->SetMagnification(1); //set the resolution of the output image (3 times the current resolution of vtk render window)<br style="" class=""> windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel<br style="" class=""> windowToImageFilter->Update();<br style="" class=""> <br style="" class=""> vtkSmartPointer<vtkPNGWriter> writer = <br style="" class=""> vtkSmartPointer<vtkPNGWriter>::New();<br style="" class=""> writer->SetFileName("screenshot2.png");<br style="" class=""> writer->SetInputConnection(windowToImageFilter->GetOutputPort());<br style="" class=""> writer->Write();<br style="" class=""> <br style="" class=""> renderWindow->Render(); <br style="" class=""> renderer->ResetCamera();<br style="" class=""> renderWindow->Render();<br style="" class=""> renderWindowInteractor->Start();<br style="" class=""> <br style="" class=""> return EXIT_SUCCESS;<br style="" class="">}<br style="" class=""><br style="" class=""><div></div></div></body></html>