Q: CSharp-Example for ViewCaptureSettings(), and CaptureToBitmap()?

Hi…,

it seams ViewCaptureSettings() isn’t working in Python at the moment: https://mcneel.myjetbrains.com/youtrack/issue/RH-85062

I assume ViewCaptureSettings() is only working in the ScriptEditor with CSharp.

Is there a little example in CSharp for the ScriptEditor, which shows how ViewCaptureSettings() with CaptureToBitmap() works?

Thanks

Michael

Hi,

How about the following link?

Hi @11159,

thank you, that helped me very much.

I was able to get this CSharp-Code to run in the ScriptEditor:

using Rhino;
using Rhino.Display;
using System;
using System.IO;

var settings = new Rhino.Display.ViewCaptureSettings( RhinoDoc.ActiveDoc.Views.ActiveView, new System.Drawing.Size( 1024, 1024 ), 300);
settings.RasterMode = true;
settings.ViewArea = ViewCaptureSettings.ViewAreaMapping.Extents;
System.Drawing.Bitmap bitmap = Rhino.Display.ViewCapture.CaptureToBitmap(settings);

if (null != bitmap)
{
    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string filename = Path.Combine(path, "Snapshot_1024x1024.png");
    bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
}

Nethertheless, I’ve failed to output my PNG without borders. I was hoping to define the rastered View by numbers, e.g. 0,0,10,10, but it didn’t work.

Attached a sample graphics, which I want totally raster to a 1024x1024 pixel PNG (without borders): wave.3dm (808.3 KB)

Any help is appreciated.

Thanks

Michael

What borders are you talking about?

When I run your code I don’t see any borders around the captured view.

I see this:

Result:

Hi @nathanletwory,

sorry about the misunderstanding.

I was talking about a 2D Top view, like in my example wave.3dm file from above.

I think I have found some workarounds with the command

_SetZoomExtentsBorder _ParallelView 1.0

to fix my border problem.

Thank you again

Michael

I still don’t understand what the border issue is.


Try my wave.3dm file.

I see.

That is actually possible with SetWindowRect(Point3d, Point3d), but even then there’s a slight border still.

// #! csharp
using Rhino;
using Rhino.Display;
using System;
using System.IO;

var settings = new Rhino.Display.ViewCaptureSettings( RhinoDoc.ActiveDoc.Views.ActiveView, new System.Drawing.Size( 1024, 1024 ), 300);
settings.SetWindowRect(new Rhino.Geometry.Point3d(0,0,0), new Rhino.Geometry.Point3d(10,10,0));
System.Drawing.Bitmap bitmap = Rhino.Display.ViewCapture.CaptureToBitmap(settings);

if (null != bitmap)
{
    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string filename = Path.Combine(path, "Snapshot_1024x1024.png");
    bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
}

I have logged this as RH-87393 ViewCapture.CaptureToBitmap captures with small border

Hi @nathanletwory,

thank you for your engagement.

// #! csharp
using Rhino;
using Rhino.Display;
using System;
using System.IO;

var settings = new Rhino.Display.ViewCaptureSettings( RhinoDoc.ActiveDoc.Views.ActiveView, new System.Drawing.Size( 1024, 1024 ), 300);
settings.RasterMode = true;
settings.DrawBackground = false; // doesn't work
settings.DrawAxis = false;       // doesn't work
settings.DrawGrid = false;       // doesn't work
settings.SetWindowRect(new Rhino.Geometry.Point3d(0,0,0), new Rhino.Geometry.Point3d(10,10,0));
System.Drawing.Bitmap bitmap = Rhino.Display.ViewCapture.CaptureToBitmap(settings);

if (null != bitmap)
{
    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string filename = Path.Combine(path, "Snapshot_1024x1024.png");
    bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
}

Now I also noticed that the ViewCaptureSettings properties DrawBackground, DrawAxis, and DrawGrid have no effect.

Is this a bug too, or I am missing something?

Michael

I don’t know, but sounds like it. I’ll tag @rajaa here in case she can enlighten us more on this topic.

1 Like

I can see what’s happening …for both extents and windowed captures. I can also see why the grid and background settings aren’t working…I’ll make that part of the same bug report.

Note: However, if you’re using SetWindowRect, then you also need to make sure that you set the ViewArea setting to “Window” as well… for example:

settings.ViewArea = ViewCaptureSettings.ViewAreaMapping.Window;

otherwise it defaults to “View”

Fixes will probably be in the next 8.x build… It’s too close to the SR20 RC release.

Thanks,
-Jeff

1 Like