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

6
  • 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". Commented Nov 19, 2018 at 9: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. Commented Nov 19, 2018 at 10:35
  • If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg. Commented Nov 19, 2018 at 10:37
  • Added a snapshot. See what I mean? Commented Nov 19, 2018 at 10:48
  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources. Commented Nov 19, 2018 at 11:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.