更新时间: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
andSystem.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 fromImage
:System.Drawing.Bitmap : System.Drawing.Image { }
Image
is anabstract
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 ofImage
.