user496949
user496949

Reputation: 86185

Can bitmap object be save as PNG or JPEG file format

Is C# bitmap supporting saving the object to JPEG or PNG file format?

Upvotes: 35

Views: 59517

Answers (3)

Roberto D V Leonardo
Roberto D V Leonardo

Reputation: 69

In addition to other comments, must add this up. I don't know if it's due to .NET version or what but to me it couldn't work. I couldn't use ImageFormat. Turned out you must also declare Using System.Drawing.Imaging

Upvotes: 0

user142162
user142162

Reputation:

Bitmap extends Image, therefore you can call: Image.Save (String, ImageFormat). For example:

using System.Drawing
// ...

Bitmap img = new Bitmap("file.jpg");
img.Save("file.png", ImageFormat.Png); // ImageFormat.Jpeg, etc

Omitting the second argument and just calling Image.Save(String) will save the image as its raw format.

Upvotes: 66

Kornilov Ruslan
Kornilov Ruslan

Reputation: 143

In addition to last post (can't comment existing post since i'm new here)

File type is NOT based off of the extension. Just try to do img.Save("result.bmp") and Image.Save("result.bmp", ImageFormat.Bmp);

and you'll see that file sizes are dramatically different.

Upvotes: 9

Related Questions