ZBuffer Bitmap Capture in C#

Hey there,
I need some help with capturing the ZBuffer of active viewport(as rendered with ShowZBuffer command) in C#.

I could get the plain image capture after switching to ZBuffer renderer in Rhino…

    Rhino.Display.RhinoView view = doc.Views.ActiveView;

    if (Save)
    {
      // Switch to ZBuffer
      Rhino.RhinoApp.RunScript("ShowZBuffer", false);
      // Capture to file
      Bitmap image = view.CaptureToBitmap();
      image.Save(Path);
      // Switch out of ZBuffer
      Rhino.RhinoApp.RunScript("ShowZBuffer", false);
    }

…but is there a way to capture the ZBuffer without actually displaying it?

Rhino.Display.ZBufferCapture class compared to ViewCapture doesn’t contain any CaptureToBitmap method, so I am a bit lost now. But I have to admit that I have little experience with C# and Rhino namespace, so it could be a very simple thing I am missing here.

Can’t test this right now but ZBufferCapture has a “GrayscaleDib” Method that returns a bitmap — perhaps this is what you need?

Nice, seems like this might be it.
Unfortunately GrayscaleDib() gives me an error.

error: A generic error occurred in GDI+. (line:0)

capture_view.gh (5.7 KB)