If you use embeed resources, you need read assembly maniffest
private void LoadImg()
{
//x is name of <Image name="x"/>
x.Source = GetResourceTextFile(GetResourcePath("Images/animaha135.gif"));
}
private string GetResourcePath(string path)
{
return path.Replace("/", ".");
}
public BitmapFrame GetResourceTextFile(string filename)
{
string result = string.Empty;
using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(String.Format("{0}.{1}",this.GetType().Assembly.GetName().Name,filename)))
{
BitmapFrame bmp = BitmapFrame.Create(stream);
return bmp;
}
}
Other solution (return Bitmap):
//Use BitmapImage bitmap = GetResourceTextFile(GetResourcePath("Images/animaha135.gif"));
public BitmapImage GetResourceTextFile(string filename)
{
string result = string.Empty;
using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(String.Format("{0}.{1}",this.GetType().Assembly.GetName().Name,filename)))
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = stream;
bi.EndInit();
return bi;
}
}
Note: Embed resources replace path => / by .