How to copy certain area from map?

1233
4
Jump to solution
06-18-2012 10:45 PM
AnatoliiTerentiev
Occasional Contributor III
Dear Gurus!
I have certain activeView on axMapControl (c# vs 2010 arcengine 2010) and want to copy certain area in powerPoint or Word document.
How I can copy the desired area , for example , in clipboard? Any reference, please?
Thanks in advance!
0 Kudos
1 Solution

Accepted Solutions
DimaShats
New Contributor III
Hi,
You can create .Net Bitmap object.

//parameter check
  if (activeView == null )
  {
    return false;
  }
  ESRI.ArcGIS.Output.IExport export =new ExportBMPClass();


  // Microsoft Windows default DPI resolution
  export.Resolution = 96;
  ESRI.ArcGIS.Display.tagRECT exportRECT = activeView.ExportFrame;
  ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
  envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
  export.PixelBounds = envelope;
  System.Int32 hDC = export.StartExporting();
  activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

Bitmap myImage = Image.FromHbitmap(new IntPtr((export as IExportBMP).Bitmap));

  // Finish writing the export file and cleanup any intermediate files
  export.FinishExporting();
  export.Cleanup();

View solution in original post

0 Kudos
4 Replies
EdgarBejarano
Occasional Contributor
Hi,

It sounds like you want to export a map as an image, which you then want to use in PowerPoint or elsewhere.

The following shows this being done.  The active view (IActiveView) can be the PageLayout or the Map, so this can be done for a map that displays in either a MapControl or PageLayoutControl in an ArcGIS Engine application you have developed. 

Export active view (complete developer sample)
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Export_active_vi...

The following snippet is easier to start with and may be all you need for exporting an active view, with adjustments, of course:

Create JPEG (hi-resolution) from ActiveView Snippet
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0049000000nv000000

or

Create JPEG from ActiveView Snippet
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Create_JPEG_from_ActiveV...

And this can help you get started with programmatically getting the exported image in Window's Clipboard:

List Files to Clipboard Snippet
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0049000000rt000000

There is also the approach of using something like this:

1.  IActiveView.Selection (returns an ISelection containing selected map features or selected graphic elements)
2.  ISelection.Copy (copies the selected items to the clipboard).  While I see you being able to paste graphic elements into an application other than ArcMap, I do not see map features copying.  This is why I suggest you exporting the map as an image and adding that to the clipboard.
3.  ISelection.Paste (copies the clipboard contents [in the activeview])
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
Is it the only way to copy ActiveView to clipboard - create Jpeg file and then copy it to clipboard?
Is it possible to copy ActiveView to bitmap object?
0 Kudos
DimaShats
New Contributor III
Hi,
You can create .Net Bitmap object.

//parameter check
  if (activeView == null )
  {
    return false;
  }
  ESRI.ArcGIS.Output.IExport export =new ExportBMPClass();


  // Microsoft Windows default DPI resolution
  export.Resolution = 96;
  ESRI.ArcGIS.Display.tagRECT exportRECT = activeView.ExportFrame;
  ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
  envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
  export.PixelBounds = envelope;
  System.Int32 hDC = export.StartExporting();
  activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

Bitmap myImage = Image.FromHbitmap(new IntPtr((export as IExportBMP).Bitmap));

  // Finish writing the export file and cleanup any intermediate files
  export.FinishExporting();
  export.Cleanup();
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
And one more question.
I can copy only entire ActiveView? Can I copy some rectangle of ActiveView?
0 Kudos