Hello all,

i have added an image as project resource, but i have a problem when trying to assign this image to image control.

the error is "cannot convert system.drawing.bitmap to system.window.media.bitmap"

how can u set the source property of image control, to an embedded Jpeg image

Thanks in advance

Re: Windows Presentation Foundation (WPF) images resources


I did something similar before. Logo.bmp was compiled as a resource into the project. In order to access it I used pack URI. More info on that here: http://msdn2.microsoft.com/en-us/library/aa970069.aspx

here is the code I used:

BitmapImage m_DefaultImage;

Uri uri = new Uri("pack://application:,,,/*AssemblyName*;component/Logo.bmp");

m_DefaultImage = new BitmapImage(uri);

//Lets suppose YourImage is Image element

YourImage.Source = m_DefaultImage;


also check ouy Trev72's post here:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1466198&SiteID=1

Re: Windows Presentation Foundation (WPF) images resources

Dat Dang

Hi, I know another way, here is what i have done:

- Put all images in an images folder with build action is Resource.
- Create a ResourceDictionary (images.xaml) like this:

Code Snippet

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

<m:BitmapImage x:Key="imgEscort" UriSource="/Images/1Escort.png" />

Then add the images.xaml into app.xaml resource (MergeDictionaries)


Code Snippet

<Image Source="{StaticResource imgEscort}" />

That's what i did.

Re: Windows Presentation Foundation (WPF) images resources


Hello Anton,

i tried your code, but it`s not working properly with me Sad

can u post a sample project and send it to my email : mr_triton@hotmail.com


Re: Windows Presentation Foundation (WPF) images resources

Tamir Khason

Recently I wrote a handy class to get resources (not only images) from the application. Try to use it - http://blogs.microsoft.co.il/blogs/tamir/archive/2007/04/05/Read-your-data-easily-from-application-resources.aspx

Re: Windows Presentation Foundation (WPF) images resources


That's a very nice solution Dat Dang, thanks!