0

I'm trying to save the previously loaded background image of a button:

Dim bm As New Bitmap(Button3.BackgroundImage)
bm.Save("c:\users\user\desktop\test.png", System.Drawing.Imaging.ImageFormat.Png)

The loaded PNG image: 186 x 186, size 51.9 KB

The Saved image file test.png: 186 x 186, size 62.3 KB

  1. Why is the saved PNG bigger than the source, while the height and width are the same?
  2. How to optimize the size to be less or equal to the original PNG?
Jongware
  • 22,200
  • 8
  • 54
  • 100
M. A.
  • 424
  • 6
  • 21
  • **1.** Because they either use different level of compression or different compression algorithms. **2.** Using built-in methods, the answer is most likely that you can't. However I don't see the point of even trying. The difference in size really isn't that big. – Visual Vincent Feb 18 '18 at 14:33
  • The reason behind the optimization is because they will be available for download through a web server, I'm looking for the minimum size for PNG. – M. A. Feb 18 '18 at 14:42
  • 3
    PNG uses a compressed data format, produced by the Deflate algorithm. It is an algorithm with a tweak parameter, you can pick whether you favor a higher compression ratio or favor spending less time on compressing. Different libraries use different choices. The Microsoft encoder does not have an option to change that parameter. Look at, say, ZopfliPNG. Freeware from Google, it is heavily biased to favor smaller sizes. – Hans Passant Feb 18 '18 at 14:44
  • 1
    Possible duplicate of [PNG Compression in .net](https://stackoverflow.com/questions/6922533/png-compression-in-net) – TnTinMn Feb 18 '18 at 15:54
  • Thanks for your comments, I was looking for a built-in method with .Net, else I'll opt for PINGO because it's better than Zopfli, also I've tested the TinyPNG Plugin for Photoshop and it's doing a great job compared to many other tools. – M. A. Feb 18 '18 at 21:11

0 Answers0