# Higher resolution for screen captures of 3D view?

**URL:** <https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880>\
**Category:** Support\
**Tags:** screen-capture\
**Created:** [October 23, 2019, 5:23pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880 "2019-10-23T17:23:25Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 19, 2023, 6:15pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/30 "2023-03-19T18:15:49Z")

</div>

You made me curious, so I tried [offscreen rendering](https://kitware.github.io/vtk-examples/site/Cxx/Utilities/OffScreenRendering/) and it basically works, although it sometimes leads to a crash when interacting with the view after rendering. But something like the code below could be added as a feature if someone wants to play with it. It could use more tweaks, but if it’s useful for people we could put it in the script repository for now.

Here’s the full res 5kx5x version:

> **[out.png](https://drive.google.com/file/d/1sJh1qNYKqzur0kPGharPd_fLKPXcLjIj/view?usp=sharing)**
>
> Google Drive file.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/7/e786811920cc3e684ad3f938add3e1a5cc22ce52.jpeg)

```auto

vtk.vtkGraphicsFactory()
gf = vtk.vtkGraphicsFactory()
gf.SetOffScreenOnlyMode(1)
gf.SetUseMesaClasses(1)
rw = vtk.vtkRenderWindow()
rw.SetOffScreenRendering(1)
ren = vtk.vtkRenderer()
rw.SetSize(5000,5000)

lm = slicer.app.layoutManager()
ren3d = lm.threeDWidget(0).threeDView().renderWindow().GetRenderers().GetItemAsObject(0)
actors = ren3d.GetActors()
for index in range(actors.GetNumberOfItems()):
    ren.AddActor(actors.GetItemAsObject(index))
lights = ren3d.GetLights()
for index in range(lights.GetNumberOfItems()):
    ren.AddLight(lights.GetItemAsObject(index))
volumes = ren3d.GetVolumes()
for index in range(volumes.GetNumberOfItems()):
    ren.AddVolume(volumes.GetItemAsObject(index))
camera = ren3d.GetActiveCamera()
ren.SetActiveCamera(camera)

rw.AddRenderer(ren)
rw.Render()

wti = vtk.vtkWindowToImageFilter()
wti.SetInput(rw)
wti.Update()
writer = vtk.vtkPNGWriter()
writer.SetInputConnection(wti.GetOutputPort())
writer.SetFileName("/tmp/out.png")
writer.Update()
writer.Write()
i = wti.GetOutput()

```

Here’s an inset of what the full resolution looks like:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/84feaa85766872c302812aa11b5fd27252c517f8.jpeg)

---

_[View the full topic](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880)._
