Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:viewcapture [2015/09/14] (current)
Line 1: Line 1:
 +====== View and Screen Capture ======
 +> **Developer:​** //​[[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to capture view and screen to an image file using the Rhino SDK.//
 +> **WARNING:​** //This example is out-of-date and needs to be replaced with RhinoCommon.//​
 +===== C# =====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  MRhinoView view = RhUtil.RhinoApp().ActiveView();​
 +  if (view == null)
 +    return IRhinoCommand.result.nothing;​
  
 +  MRhinoGetOption go = new MRhinoGetOption();​
 +  go.SetCommandPrompt("​Capture Method"​);​
 +  go.SetCommandPromptDefault("​ViewCapture"​);​
 +  int viewcap = go.AddCommandOption(new MRhinoCommandOptionName("​ViewCapture"​));​
 +  int screencap = go.AddCommandOption(new MRhinoCommandOptionName("​ScreenCapture"​));​
 +  go.GetOption();​
 +  if( go.CommandResult() != IRhinoCommand.result.success )
 +    return go.CommandResult();​
 +
 +  System.Drawing.Bitmap bmp = null;
 +
 +  if (go.Option().m_option_index == viewcap)
 +  {
 +    MRhinoDisplayPipeline pipeline = view.DisplayPipeline();​
 +    int left = 0, right = 0, bot = 0, top = 0;
 +    view.MainViewport().VP().GetScreenPort(ref left, ref right, ref bot, ref top);
 +    int w = right - left;
 +    int h = bot - top;
 +    bmp = new System.Drawing.Bitmap(w,​ h);
 +    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);​
 +    MDisplayPipelineAttributes attr = new MDisplayPipelineAttributes(pipeline.DisplayAttrs());​
 +    bool rc = pipeline.DrawToDC(g,​ w, h, attr);
 +    g.Dispose();​
 +    if (!rc)
 +      bmp = null;
 +  }
 +  else
 +  {
 +    bmp = new System.Drawing.Bitmap(1,​ 1);
 +    bool rc = view.ScreenCaptureToBitmap(ref bmp, true, false);
 +    if (!rc)
 +      bmp = null;
 +  }
 +
 +  if (bmp != null)
 +  {
 +    string mydir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);​
 +    string path = System.IO.Path.Combine(mydir,​ "​capture.png"​);​
 +    bmp.Save(path);​
 +    return IRhinoCommand.result.success;​
 +  }
 +
 +  return IRhinoCommand.result.failure;​
 +}
 +
 +</​code>​
 +
 +
 +{{tag>​Developer dotnet}}
developer/sdksamples/viewcapture.txt ยท Last modified: 2015/09/14 (external edit)