【问题标题】:Visual Studio 2017 Winforms: Load picture from project folder into Picture Box [closed]Visual Studio 2017 Winforms:将图片从项目文件夹加载到图片框[关闭]
【发布时间】:2021-03-21 13:17:40
【问题描述】:

我想在项目文件夹中创建几个文件夹来保存我的图像。然后我想把这些图片加载到一个PictureBox中。

我现在如何加载 Info_Hydraulik.png 图像?

An image with the path of the file

在此先感谢您的帮助。

火腿

【问题讨论】:

  • pictureBox1.Image = new Bitmap(this.GetType(), "Bu.Hell.Info_Hydraulik.png")。如果位图是嵌入式资源。

标签: c# winforms picturebox


【解决方案1】:

对于 Info_Hydraulik.png 在 Visual Studio 的属性中将 Build Actions 更改为 Embedded Resource

如果您使用 WinFormsPNG 加载到`PictureBox':

using System.Reflection;

Assembly assembly = Assembly.GetExecutingAssembly();
// To list all resources use this:
// string[] names = assembly.GetManifestResourceNames();
using (Stream stream = assembly.GetManifestResourceStream
    ("WindowsFormsApp1.Bu.Hell.Info_Hydraulik.png"))
{
    Image image = Image.FromStream(stream);
    pictureBox1.Image = image;
}

将示例代码中的命名空间WindowsFormsApp1调整为您的项目命名空间。

【讨论】:

  • 我必须添加 using System.IO; 并且它有效。感谢您的回复
猜你喜欢
  • 1970-01-01
  • 2019-02-09
  • 1970-01-01
  • 1970-01-01
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-26
相关资源
最近更新 更多