# Saving bitmap to file using Rhinocommon

(Ibrahim Mahmoud) #1

I’ve seen ways to create a bitmap file, such as the answers to this thread:

But I can’t seem to find the direct command to save that bitmap file to a specified folder in my computer. What commands would I use to accomplish my task?

(Menno Deij - van Rijswijk) #2
BitMap bm = view.CaptureToBitmap(new Size(600,800));
bm.Save(@"C:\path\to\bitmapfile.bmp");


(Ibrahim Mahmoud) #3

I tried that, but this seems to be a persistent error:

“A generic error occurred in GDI
http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream

My code (“Output” is a a custom class):

Rhino.Display.RhinoView View = doc.Views.ActiveView;
var bitmap = View.CaptureToBitmap(new Size(480, 480));
try
{
bitmap.Save(@“C:\test” + current + “.jpeg”, ImageFormat.Jpeg);
}
catch (Exception e)
{
Output.ToRhinoConsole(e.Message);
Output.ToRhinoConsole(e.StackTrace);
}

I also tried:

current, Rhino.Display.DefinedViewportProjection.Perspective, new Rectangle(
0, 0, 480, 480), false);

What can I do to fix this error?

(Menno Deij - van Rijswijk) #4

Do you have write access on the file c:\testcurrent.jpg?
You are trying to write to the c: root folder,

(Ibrahim Mahmoud) #5

Yes that was the problem! I couldn’t directly add any files to the root