How to: Use images which are part of a dll
I created a dll which has a public method that uses images. These images are embedded. Now when I try using the assembly in my new project, everythings works fine except the images.
I tried to run the application without using an assembly (just a normal WPF application) and it worked. So it seems, that the application does not find the embedded images from the dll.
The way I create the images used in my dll:
public void CreateBitmapImage(string uri)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(uri, UriKind.Absolute);
bitmapImage.EndInit();
image_msgIcon.Source = bitmapImage;
}
public void SetMsgImage(string msgImage)
{
if (msgImage == Error)
{
CreateBitmapImage("pack://application:,,,/CL.New;component/Images/CustomMessageBox/cross-circle.png");
}
else if (msgImage == Exclamation)
{
CreateBitmapImage("pack://application:,,,/CL.New;component/Images/CustomMessageBox/exclamation.png");
}
else
{
}
}
Now I get this error message:
Die Ressource "images/custommessagebox/cross-circle.png" kann nicht gefunden werden.
The resource "images/custommessagebox/cross-circle.png" cannot be found.
I tried it this way:
CreateBitmapImage("/CL.New;component/Images/CustomMessageBox/cross-circle.png");
...
bitmapImage.UriSource = new Uri(uri, UriKind.Relative);
... this seems to work, but the image is not displayed (no error messages).