export rendered scene to clipboard

Hi all,

I´d like to export the current content of a vtkRenderWindow to the clipboard. Is there a straightforward way to achieve this?



Do you mean capturing de screen or the actual 3D primitives in the scene?



I think by current content, you’re interested in the pixels. VTK, by itself doesn’t have a method to save pixels to the OS clipboard. However, it has the pieces necessary to build such a feature. Note that this is way easier with Qt and VTK.

vtkWindowToImageFilter is a class which captures a screenshot of the render window and outputs a vtkImageData. Here’s pseudocode

import vtk

windowCapture = vtk.vtkWindowToImageFilter()

# jpeg writer writes into this array.
jpegImage = vtkUnsignedCharArray()

jpegWriter = vtk.vtkJPEGWriter()

# Copy `jpegImage` into clipboard

After that, you can save the in-memory string (jpegImage) into the clipboard with OS-specific APIs. See Windows clipboard.

Thanks, this looks great!

I went a different route, though, which I hope is allowed to share here - it may be helpful to others.

I use VTK from inside a Qt application. And QVTKRenderWindow inherits from QOpenGLWidget. Thus,

QImage img = renderWidget->grabFramebuffer();

does the trick.

Yep, with Qt, it’s far easier. Thanks for sharing!