abrown31

Adding Images to Layout - Issue with image sizes, maintaining original aspect

Discussion created by abrown31 on Dec 15, 2011
Greetings,

I created an ArcMap Add-In and I'm using the following code to input images onto my layout, in order to display tabular chemical data for sampling location points. Right now, it only adds one .gif image. Eventually, there will be a loop to add all images in a given directory:

    Public Sub AddPictureToMap()
        Dim pmxdoc As ESRI.ArcGIS.ArcMapUI.IMxDocument = My.ArcMap.Application.Document
        Dim pPageLayout As IPageLayout = pmxdoc.PageLayout

        'Create Picture Element
        Dim pPicElement As IPictureElement = New GifPictureElement
        pPicElement.ImportPictureFromFile("C:\temp\excel\sheet0.gif")
        pPicElement.MaintainAspectRatio = True

        'Set the New Element to the Picture Element
        Dim pElement As IElement = CType(pPicElement, IElement)

        'Create Target Envelope
        Dim pEnv As IEnvelope = New EnvelopeClass
        pEnv.PutCoords(Nothing, 6, Nothing, Nothing) 'assumes that the logo is square, 2in x 2in


        'Give the Element the Target Envelope
        pElement.Geometry = pEnv

        'set the container as the pagelayout and add the element created
        Dim pGraphicsContainer As IGraphicsContainer = CType(pmxdoc.PageLayout, IGraphicsContainer)
        pGraphicsContainer.AddElement(pElement, 0)

        Dim pActiveView As IActiveView = CType(pmxdoc.PageLayout, IActiveView)
        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, pEnv)
    End Sub


My question is, how do I go about maintaining the image aspect ratio? I enforced it on the GIFPICTURELEMENT; however, the envelope changes the size when it's being created. Does anybody know a better way to deal with the envelope, and maintaining the original image proportions?

Thanks,
Andrew

Outcomes