如何从C#中的项目的资源文件夹图片 [英] How to retrieve Image from Resources folder of the project in C#

查看:1074
本文介绍了如何从C#中的项目的资源文件夹图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在资源文件夹在我的项目的一些图片,但我想图片框从项目

i Have some images in resources folder in my project but i want to change the picture box from these resource files of the project

推荐答案

考虑使用 Properties.Resources.yourImage

Properties.Resources 包含您添加作为资源(看你的项目属性,资源选项卡)的一切

Properties.Resources contains everything that you've added as a resource (see your project properties, resources tab)

除此之外,如果你嵌入图像作为资源在你的项目,你可以在他们通过调用的 GetManifestResourceStream 上,你已经嵌入图像在装配时,像

Other than that, if you embed the images as resource in your project, you can get at them by calling GetManifestResourceStream on the assembly that you've embedded the images in, something like

Stream imgStream = 
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "YourNamespace.resources.ImageName.bmp");
pictureBox.Image = new Bitmap(imgStream);



不要忘了图像标记为嵌入的资源! (你需要设置,在其属性窗口中的图像生成操作)

Don't forget to mark the image as an embedded resource! (You'll need to set the build action for the image in its properties window)

如果你发现你保持找回通过 GetManifestResourceStream ,你可能会给出错误的名称。 (它可以是很难得到的名称权)呼叫 GetManifestResourceNames 的组装;这会给你回所有的资源名称,你可以找到一个在您需要的清单。

If you're finding that you keep getting back null from GetManifestResourceStream, you may be giving the wrong name. (It can be hard to get the names right) Call GetManifestResourceNames on the assembly; that will give you back all the resource names, and you can find the one in the list that you need.

这篇关于如何从C#中的项目的资源文件夹图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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