Embed png in layout using addin

1399
4
Jump to solution
07-17-2021 10:29 PM
GregC
by
New Contributor II

I would like to add a picture (basically a company logo in png or jpg format) to new programmatically-created layouts.  I would like to embed the picture files within the addin so that users do not have to download or save the pictures to their machines.  More importantly, I need to reference the pictures where they are saved within the addin.  When trying to add a new graphic element, the only time it adds a picture is when the file path is hard coded to a location on disk. In no circumstance have I ever successfully accessed the picture file stored within the add-in.  Any advice or directions would be very much appreciated.

I've spent extensive time here: https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-content-and-image-resources#images-as-embedded-... but for the life of me I can not figure out how to reference/access those embedded image resources when I want to add them on a layout. 

Thank you!

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I tried this and found that the Url parameter for CreatePictureGraphicElement is limited as it doesn't support pack Uris as input.  I was able to get it to work by setting the 'Build' action for my embedded picture to 'Content' and the 'Copy to Output' to 'Copy if newer'.  This will unzip the actual jpg in my add-in folder as soon as the add-in is loaded by Pro and i can access the image via a 'local path'.

Wolf_0-1626795043018.png

I attached my sample for your reference.

 

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You have found the right ProGuide page. How to access  add-in resources you can find in Accessing document content chapter. First step gives you folder path of your resource file, second constructs full path of your resource. Remember to specify document content as described in chapter above.

Wolf
by Esri Regular Contributor
Esri Regular Contributor

I tried this and found that the Url parameter for CreatePictureGraphicElement is limited as it doesn't support pack Uris as input.  I was able to get it to work by setting the 'Build' action for my embedded picture to 'Content' and the 'Copy to Output' to 'Copy if newer'.  This will unzip the actual jpg in my add-in folder as soon as the add-in is loaded by Pro and i can access the image via a 'local path'.

Wolf_0-1626795043018.png

I attached my sample for your reference.

 

0 Kudos
GregC
by
New Contributor II

@Wolfand @GKmieliauskas  - Thank you both for your help!

@Wolf- your sample code was exactly what I needed.  Interestingly, I still couldn't navigate to the "MyImages/Shark.JPG", but I could find it in "Resources/Shark.JPG".  I'll mess around with it tomorrow, but for now I've got code that works!  Thank you!

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

@GregG  It depends on the 'build action' that you specify in the image's properties.  Your property probably has a build action of 'Resource' versus 'Content'.  When you specify resource the image will be embedded into your assembly as a resource and is available under 'Resources...'.  If you specify 'Content' (with an appropriate copy action) the esriaddinx will contain the jpg image file under the folder structure you use in your project file.  

Wolf_0-1626968652128.png

You can verify that the image files get attached to the esriaddinx file by 'unzipping' the file and looking into the 'Install' folder.  You should see your jpgs under that folder:

Wolf_1-1626968857814.png

 

 

0 Kudos