[英]How to: Use images which are part of a dll
如何:使用属于dll的映像
我创建了一个具有使用图像的公共方法的dll。 这些图像是嵌入的。 现在,当我尝试在新项目中使用程序集时,除图像外,其他所有东西都可以正常工作。
我尝试在不使用程序集的情况下运行该应用程序(仅是普通的WPF应用程序),并且它正常工作。 如此看来,该应用程序无法从dll中找到嵌入的图像。
我创建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
{
}
}
现在,我收到此错误消息:
Die Ressource "images/custommessagebox/cross-circle.png" kann nicht gefunden werden.
The resource "images/custommessagebox/cross-circle.png" cannot be found.
我这样尝试过:
CreateBitmapImage("/CL.New;component/Images/CustomMessageBox/cross-circle.png");
...
bitmapImage.UriSource = new Uri(uri, UriKind.Relative);
...这似乎起作用,但是未显示图像(无错误消息)。
ptk93:您是否已将图像声明为“资源”?
->解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.