Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:screencaptureview [2015/09/14] (current)
Line 1: Line 1:
 +====== Screen Capture a Viewport ======
 +====== C++, .NET ======
 +> **Summary:​** //​Demonstrates how to screen capture a viewport using the Rhino SDK.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​screencaptureview|here]]//​
 +=====See Also=====
 +[[developer:​sdksamples:​screencapture|Screen Capture All Viewports]]
 +
 +=====Question=====
 +I would like to screen capture a viewport to the file, like the **ViewCaptureToFile** command. Is this possible?
 +
 +=====Answer=====
 +Rhino'​s **ViewCaptureToFile** command does not perform a traditional screen capture. Rather, it draws geometry into a device-independent bitmap (instead of to a viewport) and then saves it to disk.
 +
 +The following sample code demonstrates how to do this.
 +
 +===== C++ =====
 +<code c++>
 +
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CWnd* pMainWnd = CWnd::​FromHandle( RhinoApp().MainWnd() );
 +  if( 0 == pMainWnd )
 +    return failure;
 +
 +  CRhinoGetFileDialog gf;
 +  gf.SetScriptMode( context.IsInteractive() ? FALSE : TRUE );
 +  BOOL rc = gf.DisplayFileDialog( CRhinoGetFileDialog::​save_bitmap_dialog,​ 0, pMainWnd );
 +  if( !rc )
 +    return cancel;
 +
 +  ON_wString filename = gf.FileName();​
 +  filename.TrimLeftAndRight();​
 +  if( filename.IsEmpty() )
 +    return nothing;
 +
 +  CRhinoView* view = RhinoApp().ActiveView();​
 +  if( view )
 +  {
 +    CRect rect;
 +    view->​GetClientRect( rect );
 +
 +    CRhinoDib dib;
 +    if( dib.CreateDib(rect.Width(),​ rect.Height(),​ 24, true) )
 +    {
 +      // Set these flags as you wish.
 +      BOOL bIgnoreHighlights = TRUE;
 +      BOOL bDrawTitle = FALSE;
 +      BOOL bDrawConstructionPlane = FALSE;
 +      BOOL bDrawWorldAxes = FALSE;
 +
 +      CRhinoObjectIterator it( CRhinoObjectIterator::​normal_or_locked_objects, ​
 +                               ​CRhinoObjectIterator::​active_and_reference_objects ​
 +                               );
 +
 +      if( view->​ActiveViewport().DisplayMode() == ON::​wireframe_display )
 +      {
 +        context.m_doc.DrawToDC( it, dib, dib.Width(),​ dib.Height(), ​
 +          view->​ActiveViewport().View(), ​
 +          bIgnoreHighlights, ​
 +          bDrawTitle, ​
 +          bDrawConstructionPlane, ​
 +          bDrawWorldAxes
 +          );
 +      }
 +      else
 +      {
 +        context.m_doc.RenderToDC( it, dib, dib.Width(),​ dib.Height(), ​
 +          view->​ActiveViewport().View(), ​
 +          bIgnoreHighlights, ​
 +          bDrawTitle, ​
 +          bDrawConstructionPlane, ​
 +          bDrawWorldAxes,​
 +          view->​ActiveViewport().GhostedShade() ​
 +          );
 +      }
 +
 +      dib.WriteToFile( filename );
 +    }
 +  }
 +
 +  return success;
 +}
 +
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/screencaptureview.txt ยท Last modified: 2015/09/14 (external edit)