algorithmic modeling for Rhino
In one of the recent releases of Grasshopper, the Export Quick Image interface was included with Grasshopper (which is pretty sweet). My question: is there a method which I can use to return a bitmap of the Rhino Viewport (like in the Toggle Viewport Frame button)?
Rhino.Display.RhinoView.CaptureToBitmap(New Size(width, height))
Or use the ViewCaptureToClipboard command...
Thanks for the quick reply. However, when I type in Rhino.Display.RhinoView... I don't see the CaptureToBitmap method. Is this public?
It is public, but you need to call it on an instance of the RhinoView class. Not the on the class itself. I.e. in the Quick Export window, I use the following code:
Private Sub UpdateViewportImage()
Dim vp As Rhino.Display.RhinoView = Nothing
If (Not String.IsNullOrEmpty(ViewportName)) Then
For Each view As Rhino.Display.RhinoView In Rhino.RhinoDoc.ActiveDoc.Views
If (view.MainViewport.Name.Equals(ViewportName, StringComparison.OrdinalIgnoreCase)) Then
vp = view
If (vp Is Nothing) Then
vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
Dim pts As PointF() = ViewportFramePoints
Dim width As Int32 = Convert.ToInt32(GH_GraphicsUtil.Distance(pts(0), pts(1)))
Dim height As Int32 = Convert.ToInt32(GH_GraphicsUtil.Distance(pts(0), pts(3)))
width = Math.Max(10, width)
height = Math.Max(10, height)
Dim capture As Bitmap = vp.CaptureToBitmap(New Size(width, height))
If (capture IsNot Nothing) Then
If (ViewportImage IsNot Nothing) Then
ViewportImage = Nothing
ViewportImage = capture
Cool. Works like a charm. Thanks so much for the help.