Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB VB.NET
I need to know why the following code alters the image.
Dim a = New Bitmap( _
My.Application.Info.DirectoryPath & "\a.png")
Dim b As New Bitmap(a)
b.Save("b.png", System.Drawing.Imaging.ImageFormat.Png)
And please don't reply
Dim b = a
I need to know why the colors in the resulting image are altered (i.e. white becomes 254, and other colors and alpha values change). I need to write this so that the resulting picture's colors match those of the original.
Posted 16-Jan-13 8:35am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have a look here:[^]
Quote from Wikipedia page:
In information technology, "lossy" compression is a data encoding method that compresses data by discarding (losing) some of it.
kamikazehighland at 16-Jan-13 13:46pm
Hmm. Thanks. I was hoping to avoid that by using PNG. I'll have to look into it further.
ProgramFOX at 16-Jan-13 13:48pm
You're welcome!
Sergey Alexandrovich Kryukov at 16-Jan-13 19:03pm
And now, I suggest how to resolve this problem by using lossless compression. Please see my solution.
Sergey Alexandrovich Kryukov at 16-Jan-13 18:51pm
Very good, a 5.
ProgramFOX at 17-Jan-13 11:40am
Thank you!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can use lossless compression, for example, in the TIFF container, which can support a number of different compression algorithms, most of them are lossless. PNG supports lossless compression as well. Please see:[^],[^],[^].
Now, .NET classes do not support PNG compression parameters. Instead, you can consider using this library:[^].
Unfortunately, this is a C library. You can use it in your .NET projects via P/Invoke or C++/CLI (mixed mode).
You might want to search more in hope to find something better.
So, you might be better off with TIFF, as .NET FCL offers a class for TIFF support:[^] (and later versions of .NET).
Good luck,
kamikazehighland at 16-Jan-13 19:31pm
Thank you both! 5 stars each. I had always understood that PNG was lossless, so this threw me off. Even the wikipedia on lossy compression doesn't mention PNG. I'm glad I've found the cause.
Sergey Alexandrovich Kryukov at 16-Jan-13 19:55pm
Great. You are very welcome.
Good luck, call again.
ProgramFOX at 17-Jan-13 11:41am
Good answer, +5!
Sergey Alexandrovich Kryukov at 17-Jan-13 11:44am
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 195
1 Peter Leow 130
2 Zoltán Zörgő 120
3 CPallini 70
4 Atish K. Singh 55
0 Sergey Alexandrovich Kryukov 9,568
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932

Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100