29

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

How to do it?

Additional information:

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

enter image description here

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

enter image description here

Except I want to add a PNG.

Otherwise my 1MB application becomes 8MB:

]=== 1MB file size ==>
]=== 8MB file size ==============================================================================================================================================>
Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

2 Answers2

42
  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

enter image description here

HEWhoDoesn'tKnow
  • 347
  • 3
  • 14
Jeff
  • 1,609
  • 3
  • 20
  • 25
  • +1 Tried as you suggested and could reproduce that it works correct. – Filburt Feb 16 '12 at 18:21
  • Can you show a screenshot showing the `Type` of the resource once added. i follow those steps and in my example a 131 kB PNG is converted to a 178 KB BMP. – Ian Boyd Feb 16 '12 at 21:20
  • @IanBoyd do you mean does mine convert to a bmp? No it does not. If you still want me to post the added resource I can though – Jeff Feb 17 '12 at 14:45
  • This answer does not work. It tries to convert the PNG to a BMP file, but that fails too. – Scott Shaw-Smith Feb 25 '14 at 20:27
  • It doesn't convert it to a BMP for me, what verzion of visual studio are you using? – Jeff Mar 07 '14 at 19:09
  • Did what you've suggested but the PNG files are still _not_ accessible using `Properties.Resources.` =( – Andreas Dec 12 '22 at 09:10
  • In VS 2022, this is done via opening the project's Resources.resx file directly, not via project menu -> properties. – a0poster May 02 '23 at 09:07
1

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.

Daniel
  • 11,315
  • 4
  • 19
  • 15