问题
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.
回答1:
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.
回答2:
The resource editor does not directly support PNG images. You have to add them as binary files like this:
IDI_BACKGROUND RCDATA "background.png"
Then you can use GDI+ to load them from your resource file. This is explained in this article (C++)
回答3:
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:
IDB_NEWFILE BITMAP "NewFile.bmp"
change it to
IDB_NEWFILE PNG "NewFile.png"
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).
来源:https://stackoverflow.com/questions/1024761/visual-studio-2008-resource-editor-is-annoying-with-pngs