Capture Viewport to Bitmap image resolution issue


I have a specific task of exporting an image of the viewport to a PNG image.
Currently I can export the image with this code (also appears in the link), AS LONG as the viewport extents are ‘smaller’ than some limit (around 200,000 millimeters in width)

import Rhino
import scriptcontext as sc
import System

def test_view_capture():
    view = sc.doc.Views.ActiveView
    if view:
        view_capture = Rhino.Display.ViewCapture()
        view_capture.Width = round(w,3) / 10
        view_capture.Height = round(crop_height[i],3) / 10
        view_capture.ScaleScreenItems = False
        view_capture.DrawAxes = False
        view_capture.DrawGrid = False
        view_capture.DrawGridAxes = False
        view_capture.TransparentBackground = True
        bitmap = view_capture.CaptureToBitmap(view)
        if bitmap:
            path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
            filename = System.IO.Path.Combine(path, "test_view_capture.png")
            bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png)

if run:

I’m wondering:

  1. are there limits to this resolution/size of the possible graphics to export?

  2. I’m specifically interesting to export my drawing in a resolution of 10mm/pixel (2.54 DPI)
    Is this possible?

  3. I know that the Rhino.Display.ViewCaptureSettings has a Resolution property but it didn’t seem to effect anything.

Any ideas would be appreciated :slight_smile:

Hi @Yafim_Simanovsky
Does using System.Drawing.Bitmap.SetResolution(xDpi, yDpi) help you here?

1 Like