【发布时间】:2014-05-28 09:26:05
【问题描述】:
如何:在项目中使用来自嵌入式程序集的图像
我创建了一个具有使用图像的公共方法的程序集。这些图像是嵌入的。现在,当我尝试在我的新项目中使用该程序集时,除了图像之外,一切正常。
我尝试在不使用程序集的情况下运行该应用程序(只是一个普通的 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);
...这似乎有效,但图像未显示(没有错误消息)。
【问题讨论】:
标签: c# .net wpf uri .net-assembly