且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么System.Drawing.Image对象和System.Drawing.Bitmap之间的区别?

更新时间:2022-10-21 10:41:07

位图继承图片

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

图片摘要类,这意味着:


  

摘要修饰符指示要修改的东西有缺失或不完整的实现。


块引用>

位图是一个密封类,这意味着:


  

当从它继承应用于类,sealed修饰符prevents其他类。


块引用>

请参阅以下内容:

  BMP位图=新位图(文件名); //作品
图片IMG =新的图像(); //编译器说:不能访问内部建筑工图像​​在这里。

这是因为图像并不意味着使用这种方式!
它只是提供了位图类的功能。

所以,总是用位图而不是图片

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 ?

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 use it this way! It just provides functionality for the Bitmap class.

So always use Bitmap instead of Image.