Visual Studio 2008 资源编辑器对 PNG 很烦人
我在 VS2008 中有一个资源 DLL 项目,其中主要包含 PNG 图像。 每次我将新图像导入资源文件时,都会收到 RC2170 错误:对于资源文件中之前存在的每个 PNG,位图文件不是 3.0 格式。
问题是,在我添加新图像之前,所有这些图像都已正常运行。 只有在我从资源文件中删除所有这些图像并再次导入它们(不变)后,它才会编译。
对于添加的每个新 PNG 文件,这种行为都会重复出现,并且随着 PNG 文件数量的增加,它会变得越来越烦人。
有人经历过类似的事情吗? 有什么解决办法吗?
顺便说一句:我实际上不需要资源编辑器将 PNG 文件识别为图像,如果这可以解决这个问题。
I have a resource DLL project in VS2008 that contains mostly PNG images. Every time I import a new image to the resource file, I get an RC2170 error: bitmap file is not 3.0 format, for every PNG that was previously in the resource file.
Thing is, all of those iamges have complied ok before I add the new image. Only after I remove all of those images from the resource file, and import them again (unchanged), it would compile.
This behavior repeats itself for every new PNG file added, and as the number of PNG files grows, it becomes increasingly annoying.
Anyone experienced anything similiar? Any solution?
BTW: I don't actually need the resource editor to recognize the PNG files as images, if that may solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据此线程,您在资源编辑器中遇到一个错误,该错误会发生变化:
IDI_DENTIFIER PNG "background.png"
至:
IDI_DENTIFIER BITMAP "background.png"
但请注意:当通过
LoadImage()
调用时,这些 PNG 资源似乎不会在 Vista 之前的操作系统上加载。 使用此资源类型可能会将您的应用程序限制为 Vista。According to this thread, you are experience a bug in the resource editor which changes:
IDI_DENTIFIER PNG "background.png"
to:
IDI_DENTIFIER BITMAP "background.png"
But beware: these PNG resources do not seem to load on pre-Vista OS when called via
LoadImage()
. Using this resource type may limit your application to Vista.资源编辑器不直接支持 PNG 图像。 您必须将它们添加为二进制文件,如下所示:
然后您可以使用 GDI+ 从资源文件中加载它们。 本文对此进行了解释(C++)
The resource editor does not directly support PNG images. You have to add them as binary files like this:
Then you can use GDI+ to load them from your resource file. This is explained in this article (C++)
我为此苦苦挣扎,但发现(至少在 Visual Studio 2012 中)您可以轻松添加 png 文件作为资源。 在资源视图中,右键单击 .rc 文件名并选择“添加资源”。 选择类型“位图”并单击“导入”。选择所需的 .png 文件。应将一个名为“PNG”的新部分添加到您的资源列表中,它应该像位图资源一样工作。
我有时会看到此失败- 如果是这样,请保存一份带有 .bmp 扩展名的 png 文件副本(或将其另存为位图),然后将其添加为位图,如上所示编辑资源文件,您将看到如下行:
将其更改为
并保存文件。 下次您查看项目的资源时,应该创建一个“PNG”部分(即使带有注释标题!)
但是,据我所知,具有透明度的 png 文件要么无法正确显示,要么在它们时会导致崩溃被加载(例如,加载到按钮中)。
I struggled with this, but found that (in Visual Studio 2012 at least) you can easily add a png file as a resource. In the Resource View, right click on the .rc file name and select "Add Resource". Select type 'Bitmap' and click 'Import." Select the .png file you want. A new section should be added to your resource list called "PNG" and it should work just like a BITMAP resource.
I have seen this fail on occasion - if so, save a copy of your png file with a .bmp extension (or save it as a bitmap) then add it as a bitmap as above. Edit the resource file and you will see a line like this:
change it to
and save the file. Next time you look at the project's resources a 'PNG' section should have been created (even with a comment header!)
But, as far as I can tell, png files with transparency will either not display correctly or will cause a crash when they are loaded (into a button, for instance).