How to export the current view


This sample takes the current active view and exports it to a JPEG file.
The code samples in this section show the fundamentals of programming with ArcObjects. A careful reading of them gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
The code can be typed or copied into the VBA environment in ArcMap or ArcCatalog, after which you can follow through with the VBA debugger.

How to use

  1. Add the code to the Click event of a UIButtonControl in ArcMap.
[VBA]
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim lScrRes As Long
lScrRes = pMxDoc.ActiveView.ScreenDisplay.DisplayTransformation.Resolution

Dim pExporter As IExporter
Set pExporter = New JpegExporter
pExporter.ExportFileName = "C:\Export.jpg"
pExporter.Resolution = lScrRes

Dim deviceRECT As tagRECT
deviceRECT = pMxDoc.ActiveView.ScreenDisplay.DisplayTransformation.DeviceFrame

Dim pDriverBounds As IEnvelope
Set pDriverBounds = New Envelope

pDriverBounds.PutCoords deviceRECT.Left, deviceRECT.bottom, deviceRECT.Right, deviceRECT.Top
pExporter.PixelBounds = pDriverBounds

Dim pCancel As ITrackCancel
Set pCancel = New CancelTracker

pMxDoc.ActiveView.Output pExporter.StartExporting, lScrRes, deviceRECT, pMxDoc.ActiveView.Extent, pCancel
pExporter.FinishExporting