如何:如果项目中的图像来自嵌入式程序集,则在它们中使用
我创建了一个程序集,该程序集具有使用图像的公共方法。这些图像是嵌入的。现在,当我尝试在新项目中使用程序集时,除图像外,其他所有东西都可以正常工作。
我尝试在不使用程序集的情况下运行该应用程序(仅是普通的WPF应用程序),并且它可以正常工作。如此看来,该程序集找不到嵌入式图像。
你能帮我吗?
编辑:我创建在我的程序集中使用的图像的方式。
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 if (msgImage == Information)
{
CreateBitmapImage("pack://application:,,,/CL.New;component/Images/CustomMessageBox/information.png");
}
else if (msgImage == Question)
{
CreateBitmapImage("pack://application:,,,/CL.New;component/Images/CustomMessageBox/question.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);
...这似乎起作用,但是未显示图像(无错误消息)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句