[vtkusers] Saving image with transparent background from Qt

Ignacio Fernández Galván jellby at yahoo.com
Tue Mar 6 11:45:41 EST 2018


Hi,

I'd like to save a PNG image with transparent background (even though 
the render window has a coloured background). I've checked the example 
at https://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot and I 
can get what I want from a simple python+VTK application. But when I add 
Qt into the mix, the image I get has opaque background. The relevant 
code is simply:

renWin = self.vtkWidget.GetRenderWindow()
renWin.SetAlphaBitPlanes(1)
wti = vtk.vtkWindowToImageFilter()
wti.SetInput(renWin)
wti.SetInputBufferTypeToRGBA()
wti.ReadFrontBufferOff()
wti.Update()
w = vtk.vtkPNGWriter()
w.SetFileName('screenshot.png')
w.SetInputConnection(wti.GetOutputPort())
w.Write()

Can anyone get it to work?

Ignacio


More information about the vtkusers mailing list