marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

Taking screenshot as array discards transparency #1199

Open miek0tube opened 1 week ago

miek0tube commented 1 week ago

Taking a offscreen screenshot works just fine when saving it to a file. However, when you specify "asarray" parameter, transparency information is lost: plotter.show( mesh, viewup='y', ).screenshot('./_screenshot.png') # works fine saving a PNG file

img = plotter.show( mesh, viewup='y', ).screenshot('./_screenshot.png', ararray=True) # returns 3-channel RGB image with no tranpsarency

The cause is in file.io.py here (starting from line 1822): if asarray: pd = w2if.GetOutput().GetPointData() npdata = utils.vtk2numpy(pd.GetArray("ImageScalars")) npdata = npdata[:, [0, 1, 2]] #### ----------- DISCARDING 4th channel --------- ######## ydim, xdim, _ = w2if.GetOutput().GetDimensions() npdata = npdata.reshape([xdim, ydim, -1]) npdata = np.flip(npdata, axis=0) return npdata When the marked line is removed, everything works as supposed to.