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

标签 c# winforms image bitmap drawing

我很困惑 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/

相关文章:

c# - “Mock” 数据库和 “Real” 数据库行为之间的差异

c# - WPF:将转换器应用于 ItemsSource

c# - Ruby 相当于 C# 的 ??运算符(operator)

c# - 如何将经过 UTF-8 编码两次的字符串解码为简单的 UTF-8?

c# - 如何在 C# 中隐藏/阻止选项卡?

C# windows 应用程序,如何保存和恢复子窗体的位置

.net - 即时修改 app.config

image - 无法加载 YouTube 缩略图的网络图像 Flutter Web

带有 HTTPS (SSL) 的图像源 URI 有效,HTTP 无效(React Native v0.30.0)

PHP MySQL 无法从数据库中找到我的图像