如何:如果项目中的图像来自嵌入式程序集,则在它们中使用

gpuk360

如何:如果项目中的图像来自嵌入式程序集,则在它们中使用

我创建了一个程序集,该程序集具有使用图像的公共方法。这些图像是嵌入的。现在,当我尝试在新项目中使用程序集时,除图像外,其他所有东西都可以正常工作。

我尝试在不使用程序集的情况下运行该应用程序(仅是普通的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);

...这似乎起作用,但是未显示图像(无错误消息)。

凯文

您应该阅读WPF文档中的Pack URI

基本上,Uri当您引用其他程序集中的资源时,应该使用s。如文档中所述,请尝试使用类似以下内容的方法:

pack://application:,,,/ReferencedAssembly;component/Image.png 

或者

pack://application:,,,/ReferencedAssembly;component/Subfolder/Image.png

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在程序中使用来自resources.resx的嵌入式文件

Xamarin表单:如何在PCL Project中使用嵌入式资源获取图像

无法从Google App Engine项目中显示html中的嵌入式图像

如何在angular2应用程序中使用Braintree的嵌入式UI?

如何在springboot应用程序中使用嵌入式mongoDB进行junit测试?

如何在iOS的嵌入式专用框架和应用程序中使用静态库

如何从2个嵌入式不同项目中运行一个项目

如何使用xsl从xml文件读取嵌入式图像

如何在 Vite 中使用嵌入式 Webassembly?

如何在嵌入式框架中使用Cocoapods?

Netbeans 8.2:如何在 osx 上的 Spring.Boot 项目中停止嵌入式 Tomcat?

Magnific Popup Gallery:如何在嵌入式类型项目中显示计数器?

从共享项目中获取嵌入式资源

如何从嵌入式资源加载图像

在嵌入式项目上使用Valgrind

使用mailR发送嵌入式图像

如何在Xamarin iOS项目中使用签名程序集(PCL)?

如何将图像放置在嵌入式列表中的每个项目之前?

如何使用Laravel 5.8在电子邮件中嵌入嵌入式图像

如何在注释中使用多个组件类型(嵌入式,可嵌入)

在React JS中使用嵌入式CSS设置背景图像URL

MEF-从嵌入式DLL获取程序集

需要引导程序类“嵌入式响应项目”来使用结构画布元素

如何在VS 2015 RC中将嵌入式资源添加到“类库(包)”项目中?

如何使用嵌入式视图模型

在 Keil 中使用 Arcom 实现 C 嵌入式程序的目标和电路板

g ++:在嵌入式应用程序中使用单例

在Navbar引导程序中使用SVG嵌入式图标的对齐问题

嵌入式图像的BitmapSource