Use embedded image as GraphicElement on Layout

11-16-2020 07:45 PM
New Contributor

I am trying to add a number of PNG images to a Layout as GraphicElements, but I want to use images I've saved as embedded resources. All the examples I've seen use an absolute file path to the user's directory.  I'd like the GraphicElement to pull the image file from the add-in, not the user's machine.  My solution works perfectly when I use an absolute file path to my own machine - how do I modify the code to pull the embedded image resource instead? 

Note - the embedded image is listed as "resource" and "do not copy", although I've tried many combinations. 

//  Hardcoding the path (for now)
string picPath = @"C:\User\ABC123\CompanyLogo.png";  //This works
string picPath = "pack://application:,,,/LayoutToolAddin;component/Images/CompanyLogo.png";  // Does NOT work.
GraphicElement picElm = LayoutElementFactory.Instance.CreatePictureGraphicElement(newLayout, env_logo, picPath);


Resources I've checked:

My apologies if I've missed something obvious.  This is the first time I've ever worked in C#. 

0 Kudos
0 Replies