Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can bitmap object be save as PNG or JPEG file format

Tags:

c#

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

like image 217
user496949 Avatar asked Feb 26 '11 02:02

user496949


People also ask

Is a PNG file a bitmap?

A png (Portable Network Graphics) file is a raster or bitmap image file format. A raster image is made up of a fixed number of pixels [or building blocks] that form a complete image. The image cannot be enlarged without distortion occurring.

Is bitmap available in JPEG Format?

JPEG and Bitmap are two different types of format used to store the images. JPEG: The full form JPEG is Joint Photographic Experts Group. And there are two extensions used to store image in this format, these are .

What can a bitmap image be saved as?

Common bitmap image file types include JPEG , GIF and PNG .


2 Answers

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.

like image 171
Tim Cooper Avatar answered Sep 28 '22 15:09

Tim Cooper


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.

like image 26
Kornilov Ruslan Avatar answered Sep 28 '22 15:09

Kornilov Ruslan