有时我们想把重建的图像放在自定义背景上,就需要获取一张背景透明的重建图像。
实现方法:
1、首先将renderwindow的alpha通道打开。
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(ren);
renWin->SetAlphaBitPlanes(1);
2、保存图像时开启RGBA选项,然后保存为png图像。
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
vtkSmartPointer<vtkWindowToImageFilter>::New();
windowToImageFilter->SetInput(renWin);
windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
//windowToImageFilter->SetInputBufferTypeToRGB();
windowToImageFilter->ReadFrontBufferOff(); // read from the back buffer
windowToImageFilter->Update();
vtkNew<vtkPNGWriter> writer;
writer->SetFileName("test.png");
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
writer->Write();