Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Uri reference to a Resource image embedded in the assembly itself? [duplicate]

Tags:

c#

uri

image

wpf

In my assembly project I have a .png image which it's Build Action is set to Resource.

Now I want to make the following:

_myIcon = new BitmapImage(new Uri(**path to the image embedded on the assembly**));

I have looked into the examples in http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx but as far as I tried gives me "Invalid URI: The format of the URI could not be determined.". I don't think this should be a complicated matter, am I taking the wrong approach?

like image 214
André Santaló Avatar asked Oct 17 '25 01:10

André Santaló


1 Answers

The other answer is valid but doesn't produce a BitmapSource.

The correct answer, given that I have a folder called Images and inside an Image with the Build Action set to Resource, is to use a Resource File Pack URI:

_myIcon = new BitmapImage(new Uri("pack://application:,,,/Images/MyImage.png");
like image 57
André Santaló Avatar answered Oct 18 '25 14:10

André Santaló



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!