You are here: > ESRI Forums > arcgis engine forums > Thread Replies

ArcGIS Engine Forums

ArcGIS Engine: ArcObjects COM API forum

Question about graphics output   Dave Southern Feb 04, 2009
Re: Question about graphics output   Neil Clemmons Feb 05, 2009
Re: Question about graphics output   Dave Southern Feb 05, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Question about graphics output 
Author Dave Southern 
Date Feb 04, 2009 
Message I have the code below that outputs the displayed area of the axMapControl to a bitmap file.

Everything works fine until the width and height of the output size reaches a certain point, and then I get an error when trying to create the new drawing.bitmap file. It will say 'parameter is not valid'. There's no reference to this in the MS documentation, but I'm assuming it means the size of the bitmap is too big.

Is there a way to check the size and make sure it doesn't exceed what the system will allow? I don't know if the limitation is due to screen resolution, memory, or what.

Perhaps also there's a way to change something on the display so that it doesn't show up so big.

Any assistance would be appreciated. 
 
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
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Question about graphics output 
Author Neil Clemmons 
Date Feb 05, 2009 
Message Have you tried exporting the active view using a pure ArcObjects method (ie, IExport)? There is an example named Export to JPEG in the dev samples that can easily be changed to export to bitmap or any of the other supported file types. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Question about graphics output 
Author Dave Southern 
Date Feb 05, 2009 
Message I didn't even know that interface and coClasses existed. That fixed the issue.

That example code is awfully ugly, though. I had to weed out all the extraneous stuff I didn't need and get to the bare bones.