gpt4 book ai didi

c# - System.Drawing.Image 和 System.Drawing.Bitmap 有什么区别?

转载 作者:可可西里 更新时间:2023-11-01 08:20:01 24 4
gpt4 key购买 nike

我很困惑 System.Drawing.ImageSystem.Drawing.Bitmap 之间有什么不同

有人可以解释这两种类型之间的主要区别吗?

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

最佳答案

Bitmap 继承自 Image:

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

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

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

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

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

请参阅以下内容:

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

这是因为 Image 不应该以这种方式使用。它只是为 Bitmap 类提供功能。

因此在处理像素化图像(如 jpeg、png、bmp 等)时使用 Bitmap

如果您不希望在您的方法中使用特定类型的图像并且 Image 的方法已经足够,请使用更通用的 Image 作为参数类型。然后,此方法还将接受从 Image 继承的其他类,例如 Metafile

关于c# - System.Drawing.Image 和 System.Drawing.Bitmap 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19678195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com