Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
im trying to add a image from resource folder to a image box, how ever if i gave the full URl of the image without referring to the resource file it is working

What I have tried:

ImageSource imageSource = new BitmapImage(new Uri(@"Images/Icon Set/CloudyDay.jpg", UriKind.Relative));

imgwicon.Source = imageSource;
Posted
Updated 28-Sep-17 22:40pm
Comments
Graeme_Grant 28-Sep-17 23:25pm    
You say it is working, so what is the problem?
Member 13049972 29-Sep-17 1:11am    
no its not working mate! only working if i gave the full URL from the local hard disk. how do i get the referance from the resource folder inside the solution
Graeme_Grant 29-Sep-17 2:02am    
You needed to mention this in the question details... Solution posted below.

The easiest way to specify a path to an image to be used in an Image control is to do the following:

1. Embed the image as a binary resource in your project
2. Set the Build Action of the image to Resource
3. Just use the filename as the image’s Source (prefix path if in subfolder)
4. Do not distribute the image with your executable (it’s embedded)

Just use the filename in the Image tag:
XML
<Image Source="CloudyDay.jpg"/>

With path:.
XML
<Image Source="Images/Icon Set/CloudyDay.jpg"/>
 
Share this answer
 
v3
Comments
George Swan 11-Oct-17 4:16am    
Good answer. The term ‘embedded’ may be confusing because there are both ‘Resource’ and ‘Embedded Resource’ options for creating a Resource. I feel that the best option for WPF is ‘Resource’ because it integrates better with WPF’s file management service. Both options create an embedded resource, in the sense that they become an integral part of the assembly.
ImageSource imageSource = new BitmapImage(new Uri(@"Images/Icon Set/CloudyDay.jpg", UriKind.Relative));

imgwicon.Source = imageSource;


here remove the ,
UriKind.Relative


thats all!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900