NeVada
NeVada

Reputation: 127

Why does the Bitmap in C# expand an image's file size when saving it?

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.

e.g. 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);
    }
}

Upvotes: 0

Views: 55

Answers (1)

Marina Melin
Marina Melin

Reputation: 172

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.

Upvotes: 2

Related Questions