Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between System.Drawing.Image and System.Drawing.Bitmap?

I am confused what's the different between System.Drawing.Image and System.Drawing.Bitmap

Can someone explain the major difference between those two types ?

And Why to use System.Drawing.Bitmap instead of System.Drawing.Image ?

like image 311
Kas Avatar asked Oct 30 '13 09:10

Kas


People also ask

What is System drawing image?

The System. Drawing. Imaging namespace provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System. Drawing namespace.

What is System drawing bitmap?

Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes. A Bitmap is an object used to work with images defined by pixel data.

What is bitmap image in C#?

A Bitmap file displays a small dots in a pattern that, when viewed from afar, creates an overall image and that Bitmap image is a grid made of rows and columns where a specific cell is given a value that fills it in or leaves it blank thus creating an image out of the data.


1 Answers

Bitmap inherits from Image:

System.Drawing.Bitmap : System.Drawing.Image
{ }

Image is an abstract class, this means:

The abstract modifier indicates that the thing being modified has a missing or incomplete implementation.

Bitmap is a sealed class, this means:

When applied to a class, the sealed modifier prevents other classes from inheriting from it.

See the following:

Bitmap bmp = new Bitmap(filename); // Works
Image img = new Image(); // The compiler says: "Cannot access internal constructer 'Image' here.

This is because Image is not meant to be used this way. It just provides functionality for the Bitmap class.

Thus use Bitmap when dealing with pixelated images, like jpeg, png, bmp, etc.

If you expect no specific type of image in your method and the methods of Image are sufficient, use the more general Image as parameter type. This method will then accept other classes inheriting from Image as well, for example Metafile.

like image 199
Andy Avatar answered Oct 12 '22 05:10

Andy