protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var view = doc.Views.ActiveView; if (null == view) { return(Result.Failure); } var view_capture = new ViewCapture { Width = view.ActiveViewport.Size.Width, Height = view.ActiveViewport.Size.Height, ScaleScreenItems = false, DrawAxes = false, DrawGrid = false, DrawGridAxes = false, TransparentBackground = true }; var bitmap = view_capture.CaptureToBitmap(view); if (null != bitmap) { var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var filename = Path.Combine(path, "SampleCsViewCapture.png"); bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png); } return(Result.Success); }
public static string CaptureImage(string pathToFile, string fileName, bool transparent, bool activate) { string result = "Failure"; if (activate == false) { return("Not Activated"); } else if (pathToFile == "") { return("Path does not exist"); } else if (!System.IO.Directory.Exists(pathToFile)) { return("Path does not exist"); } RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; if (null == view) { return(result); } var view_capture = new ViewCapture { Width = view.ActiveViewport.Size.Width, Height = view.ActiveViewport.Size.Height, ScaleScreenItems = false, DrawAxes = false, DrawGrid = false, DrawGridAxes = false, TransparentBackground = transparent, }; System.Drawing.Bitmap bitmap = view_capture.CaptureToBitmap(view); if (null != bitmap) { if (!pathToFile.EndsWith("\\")) { pathToFile = pathToFile + "\\"; } var filename = pathToFile + fileName + ".png"; bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png); return("Success"); } return(result); }
public static Bitmap GeneratePreview(NestedBlock nested, RhinoDoc doc) { var view = doc.Views.ActiveView; var viewCapture = new ViewCapture { Height = Settings.BlockManagerPreviewHeight, Width = Settings.BlockManagerPreviewWidth }; // store old settings var cameraLocation = view.ActiveViewport.CameraLocation; var cameraTarget = view.ActiveViewport.CameraTarget; var cameraDirection = cameraTarget - cameraLocation; var cameraUp = view.ActiveViewport.CameraUp; var displayMode = view.ActiveViewport.DisplayMode; view.ActiveViewport.NextViewProjection(); view.ActiveViewport.PushViewProjection(); view.ActiveViewport.SetProjection(Settings.BlockManagerPreviewProjection, null, false); view.ActiveViewport.DisplayMode = Settings.BlockManagerPreviewDisplayModeDescription; var conduit = new BlockPreviewConduit(nested); conduit.Enabled = true; doc.Views.RedrawEnabled = false; var bb = conduit.GetReferenceBoundingBox(); bb.Inflate(0.8, 0.8, 0.8); //view.ActiveViewport.SetCameraLocation(bb.Corner(true, true, true), false); //view.ActiveViewport.SetCameraTarget(bb.Center, false); view.ActiveViewport.ZoomBoundingBox(bb); view.Redraw(); var image = viewCapture.CaptureToBitmap(view); conduit.Enabled = false; var prev = view.ActiveViewport.PreviousViewProjection(); //var popped = view.ActiveViewport.PopViewProjection(); view.ActiveViewport.CameraUp = cameraUp; view.ActiveViewport.SetCameraLocation(cameraLocation, false); view.ActiveViewport.SetCameraDirection(cameraDirection, false); view.ActiveViewport.SetCameraTarget(cameraTarget, false); view.ActiveViewport.DisplayMode = displayMode; doc.Views.RedrawEnabled = true; return(image); }
public Bitmap CaptureToBitmap(string vieportName, bool drawAxes, bool drawGrid, bool drawGridAxes, bool transparentBackground) { var view = Rhino.RhinoDoc.ActiveDoc.Views.Find(vieportName, false); var view_capture = new ViewCapture { Width = view.ActiveViewport.Size.Width, Height = view.ActiveViewport.Size.Height, ScaleScreenItems = false, DrawAxes = drawAxes, DrawGrid = drawGrid, DrawGridAxes = drawGridAxes, TransparentBackground = transparentBackground }; return(view_capture.CaptureToBitmap(view)); }
private Image GetPreviewHelper(InstanceDefinitionConduit conduit, int width, int height) { var doc = RhinoDoc.ActiveDoc; var view = doc.Views.ActiveView; var viewCapture = new ViewCapture { Height = height, Width = width }; // store old camera settings var settings = new CameraSettings(view); // set projection for viewcapture view.ActiveViewport.SetProjection(DefinedViewportProjection.Perspective, null, false); // get conduit and enable it conduit.Enabled = true; // disable redraw doc.Views.RedrawEnabled = false; // zoom to reference boundingbox var bb = conduit.GetReferenceBoundingBox(); bb.Inflate(0.8, 0.8, 0.8); view.ActiveViewport.ZoomBoundingBox(bb); // redraw and capture view.Redraw(); var image = viewCapture.CaptureToBitmap(view); // disable the conduit conduit.Enabled = false; // reset view changes settings.ApplySettings(view); // re-enable drawing doc.Views.RedrawEnabled = true; // return captured imaged return(image); }
public void Capture(string vieportName, string pathToFile, bool drawAxes, bool drawGrid, bool drawGridAxes, bool transparentBackground) { var view = Rhino.RhinoDoc.ActiveDoc.Views.Find(vieportName, false); var view_capture = new ViewCapture { Width = view.ActiveViewport.Size.Width, Height = view.ActiveViewport.Size.Height, ScaleScreenItems = false, DrawAxes = drawAxes, DrawGrid = drawGrid, DrawGridAxes = drawGridAxes, TransparentBackground = transparentBackground }; var bitmap = view_capture.CaptureToBitmap(view); if (null != bitmap) { bitmap.Save(pathToFile, System.Drawing.Imaging.ImageFormat.Png); } }