从 C# 项目的资源区域加载图像

问题描述:

我的项目中有一个图像存储在 Resources/myimage.jpg 中.如何将此图像动态加载到 Bitmap 对象中?

I have an image in my project stored at Resources/myimage.jpg. How can I dynamically load this image into Bitmap object?

您在使用 Windows 窗体吗?如果您使用属性/资源 UI 添加了图像,则可以从生成的代码访问图像,因此您可以简单地执行以下操作:

Are you using Windows Forms? If you've added the image using the Properties/Resources UI, you get access to the image from generated code, so you can simply do this:

var bmp = new Bitmap(WindowsFormsApplication1.Properties.Resources.myimage);