How to include markup annotations in high-resolution screen capture

That’s a great idea!

You can resize the window to any size - does not matter how large your display is (I’ve tested it on Windows, I don’t see a reason why it would not work on other operating systems or window managers). So, a code snippet to render a 3D view at arbitrarily high resolution:

Set up a 3D view outside the main view layout:

# Switch to a layout that has a window that is not in the main window
layoutManager = slicer.app.layoutManager()
originalLayout = layoutManager.layout
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutDualMonitorFourUpView)
# Maximize the 3D view within this layout
viewLogic = slicer.app.applicationLogic().GetViewLogicByLayoutName("1+")
viewNode = viewLogic.GetViewNode()
layoutManager.addMaximizedViewNode(viewNode)

Now set up visualization in the 3D view (e.g., drag-and-drop an image to show it with volume rendering).

# Resize the view
viewWidget = layoutManager.viewWidget(viewNode)
# Parent of the view widget is the frame, parent of the frame is the docking widget
layoutDockingWidget = viewWidget.parent().parent()
originalSize = layoutDockingWidget.size
layoutDockingWidget.resize(3000,3000)
# Capture the view
import ScreenCapture
cap = ScreenCapture.ScreenCaptureLogic()
cap.captureImageFromView(viewWidget.threeDView(), "c:/tmp/test.png")
# Restore original size and layout
layoutDockingWidget.resize(originalSize)
layoutManager.setLayout(originalLayout)

Since this is a regular 3D view, everything will just work - markups will appear the same way as in any other view, you can use it with screen capture module to capture videos, etc.

4 Likes