tags:

views:

51

answers:

2

Hi Iam loading image at runtime.I have the problem where i have to place the image in folder.Actually i put it in folder named as Image.But it shows the error that it can not find image in folder ...bin\debug\HH.bmp.

So i pasted it in debug folder and works fine. But when i take EXE out of Debug folder and when i run it,it does not work. Why? Then how can i add image in such case?

Is there any way to add image in resource file, Like in MFC..

src1 = @"HH.bmp";
Img1.Source = new ImageSourceConverter().ConvertFromString(src1 ) as ImageSource;
A: 

This is very similar to another question. Check out http://stackoverflow.com/questions/347614/wpf-image-resources

EDIT

<Image Source="../Images/icon.png" />
Steve Danner
I used like "src1 = @"pack://application:,,,/WpfApp;component/data/HH.bmp";Its works fine.But when i convert it to Control Library,it didnot works.It shows error.that cannot load assembly
Anu
Can you set the image property in the XAML instead? The way we do it here is to set it like I have in the edit of my answer...
Steve Danner
A: 

If you run this application will search the image in the current Assembly directory. just try like this <Image source="/yournamespace;component/Images/Close.png"> there should be an image folder with close.png in the solution. No need of the image or image folder in the debug folder.

Kishore Kumar
It show me the error Could not find a part of the path 'C:\WpfApp;component\data\HH.png'.And im doing this in C# coding not in XAML
Anu
k just try thisImgControl.Source=new BitmapImage(new URI(@"/yournamespace;component/Images/Close.png",UriKind.Relative));
Kishore Kumar