如何将图像添加到资源的方式不同 [英] Different way how add image to resources

查看:128
本文介绍了如何将图像添加到资源的方式不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我发现了两种将图像添加到资源的方法。

Hi I found 2 two ways how add image to resources.

首先是:例如,我创建文件夹图像并将一些图像添加到此文件夹,在Resources上设置图像构建操作。像这里的东西:

First is: For example I create folder images and add some images to this folder, set images build action on Resources. Something like here:

http://www.codewrecks.com/blog/index.php/2010/07/23/bind-an-image-to-a -property-in-wpf /

第二种方法是使用Resources.resx并使用AddResources - > AddExistingFile。

And second way is use Resources.resx and use AddResources -> AddExistingFile.

结果是否相同?

对不起我的英语。

推荐答案

不,它不一样。

WPF资源应该使用资源构建操作。 Resx资源(也称为嵌入式资源)由Windows窗体使用,而不是WPF。他们解析为 System.Drawing.Bitmap ,但WPF需要一个 System.Windows.Media.ImageSource ,所以你不能直接在WPF中使用Resx图像(但是您可以使用<<转换从位图转换为 ImageSource code> System.Windows.Interop.Imaging class)

WPF resources should use the "Resource" build action. Resx resources (aka "Embedded resource") are used by Windows Forms, not WPF. They resolve to a System.Drawing.Bitmap, but WPF needs a System.Windows.Media.ImageSource, so you can't use Resx images directly in WPF (you can however convert from a Bitmap to an ImageSource, using the System.Windows.Interop.Imaging class)

这篇关于如何将图像添加到资源的方式不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆