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

Kas*_*Kas 13 c# drawing image bitmap winforms

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 ?

为什么要使用System.Drawing.Bitmap而不是System.Drawing.Image?

And*_*ndy 13

Bitmap继承自Image:

System.Drawing.Bitmap : System.Drawing.Image
{ }
Run Code Online (Sandbox Code Playgroud)

Image 是一个抽象类,这意味着:

abstract修饰符指示正在修改的事物具有缺失或不完整的实现.

Bitmap 是一个密封的类,这意味着:

应用于类时,sealed修饰符会阻止其他类继承它.

请参阅以下内容:

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

这是因为Image不打算以这种方式使用.它只是为Bitmap类提供功能.

因此总是使用Bitmap而不是Image.

  • 如果我可以添加 - 不要害怕将`Bitmap`类型的变量传递给以`Image`作为参数的函数...因为`Bitmap`是`Image`,它会接受它.例如,`g.DrawImage(mybitmap,0,0)`对于`bitmap`类型的`mybitmap`是有效的(这里,`g`是`Graphics`类型,`DrawImage`是`Image`作为参数). (6认同)