0

I have done quite a bit of research but still cannot figure this out.

I have made a program that I would like to include a jpg image as an embedded resource, in the exe file. The reason is I don't want anyone tampering or changing the image once the program is released, and also when I distribute the program it would be good if there was only one file to send.

This is what I have at the moment, which works fine when loading an image on the hard drive.

<Border.Resources>
   <BitmapImage x:Key="Logo" UriSource="C:\Users\gmcco\Pictures\Development\Logo.jpg"/>
</Border.Resources>
<Grid>
   <Image Source="{StaticResource Logo}"/>
</Grid>

I have loaded the image into the program and changed the properties to make it an embedded resource, but cannot seem to use it.

How do you reference a embedded image in XAML please?

Snapshot

  • 2
    You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be `Resource` (for an assembly resource), and the image should be loaded in XAML by a path like `/Images/Logo.jpg`, where the image file is located in a project folder named "Images". – Clemens Nov 19 '18 at 09:24
  • I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:\Images\Logo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again. – Grant McConville Nov 19 '18 at 10:35
  • If the image file is in a folder named "Resources", the path should obviously be `/Resources/Logo.jpg`. – Clemens Nov 19 '18 at 10:37
  • Added a snapshot. See what I mean? – Grant McConville Nov 19 '18 at 10:48
  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources. – Clemens Nov 19 '18 at 11:14
  • It works. I am still not 100% how, but it does work. Thanks for your help. – Grant McConville Nov 20 '18 at 08:40

0 Answers0