I'm working on a project which requires manipulating images in different ways by modifying their pixel data array. Working with the Bitmap class in C# is pretty straightforward, but saving a Bitmap seems to have a strange behavior.
Even for an image that is not retouched in any way, its size increases upon saving it.
eg source.png - 2MB
becomes destination.png - 3MB
class Program
{
static void Main(string[] args)
{
Bitmap bitmap = new Bitmap(@"SomePath\source.png");
bitmap.Save(@"SomePath\destination.png", ImageFormat.Png);
}
}
This sometimes happens if an original image was created in a 3rd party software which applied compression algorithm when saving the image. When you open this image as a bitmap object, the compression is "undone". And upon saving, C# does not apply the same compression algorithm which was applied by the 3rd party software causing a resulting image to expand in size.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.