| |
Public Function DrawToImage(ByVal Scale As Single, ByVal Envelope As ESRI.ArcGIS.Geometry.IEnvelope) As Drawing.Image
Dim ptFrom As New Drawing.Point
Dim ptTo As New Drawing.Point
Dim OutputStart As Drawing.Point
Dim OutputSize As Drawing.Size
Dim pEnvBackup As ESRI.ArcGIS.Geometry.IEnvelope
'backup the current envelope, then
'apply our scale to the map control
pEnvBackup = Me.Extent
Me.MapScale = Scale
'get the size of the bounds to be drawn in screen coordinates
Me.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(Envelope.UpperLeft, ptFrom.X, ptFrom.Y)
Me.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(Envelope.LowerRight, ptTo.X, ptTo.Y)
'construct the output rectangle bounds
OutputStart = New Drawing.Point(1, 1)
OutputSize = New Drawing.Size(Math.Abs(ptTo.X - ptFrom.X), Math.Abs(ptTo.Y - ptFrom.Y))
'create the output image and get the image graphics
DrawToImage = New Drawing.Bitmap(OutputSize.Width, OutputSize.Height)
Using g As Drawing.Graphics = Drawing.Graphics.FromImage(DrawToImage)
'floodfill the background with white
g.FillRectangle(Drawing.Brushes.White, g.ClipBounds)
'output the map to the bitmap
Me.ActiveView.Output(g.GetHdc.ToInt32, 0, Conversion.ToTAGRect(New Drawing.Rectangle(OutputStart, OutputSize)), Envelope, Nothing)
g.ReleaseHdc()
End Using
'reapply the original envelope
Me.Extent = pEnvBackup
End Function
|