.net 如何在 Visual Studio 2010 中添加 PNG 资源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9316549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:14:54  来源:igfitidea点击:

How to add PNG resource in Visual Studio 2010?

.netvisual-studiovisual-studio-2010resources.net-assembly

提问by Ian Boyd

I have a PNG (i.e. a compressed image) that I'd like to include in my assembly (i.e. application).

我有一个 PNG(即压缩图像),我想将其包含在我的程序集(即应用程序)中。

How to do it?

怎么做?

Additional information:

附加信息:

I tried adding a PNG resource to my assembly in Visual Studio 2010:

我尝试在 Visual Studio 2010 中向我的程序集添加一个 PNG 资源:

enter image description here

在此处输入图片说明

But that didn't work, as Visual Studio converts it to an uncompressed bitmap:

但这不起作用,因为 Visual Studio 将其转换为未压缩的位图:

enter image description here

在此处输入图片说明

Except I want to add a PNG.

除了我想添加一个PNG。

Otherwise my 1MB application becomes 8MB:

否则我的 1MB 应用程序变成 8MB

]=== 1MB file size ==>
]=== 8MB file size ==============================================================================================================================================>

回答by Jeff

  1. Go to the project menu -> properties.
  2. Select the resources tab
  3. Make sure Images is selected first.
  4. Click the arrow beside 'add resource'
  5. New Image (Select from Image File Types)
  6. Find the PNG
  1. 转到项目菜单 -> 属性。
  2. 选择资源选项卡
  3. 确保首先选择图像。
  4. 单击“添加资源”旁边的箭头
  5. 新图像(从图像文件类型中选择)
  6. 找到PNG

enter image description here

在此处输入图片说明

回答by Daniel

The only way I could make this work, is by removing the file extension from the PNGs. That way Visual Studio doesn't recognize the files as images, and leaves them untouched.

我可以完成这项工作的唯一方法是从 PNG 中删除文件扩展名。这样,Visual Studio 就不会将文件识别为图像,而不会影响它们。