图像与位图类
我无法理解 Image
类和 Bitmap
类之间的差异。 现在,我知道 Bitmap 继承自 Image,但据我了解,两者非常相似。 有人能解释一下吗?
I have trouble understanding the differences between the Image
class and the Bitmap
class. Now, I know that the Bitmap
inherits from the Image
but from what I understand both are very similar. Can anyone shed some light on this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bitmap 类是Image 类的实现。 Image类是一个抽象类;
Bitmap 类包含 12 个构造函数,它们通过不同的参数构造 Bitmap 对象。 它可以从另一个位图和图像的字符串地址构造位图。
请参阅此综合示例了解更多内容。
The Bitmap class is an implementation of the Image class. The Image class is an abstract class;
The Bitmap class contains 12 constructors that construct the Bitmap object from different parameters. It can construct the Bitmap from another bitmap, and the string address of the image.
See more in this comprehensive sample.
这是一个澄清,因为我看到代码中所做的事情确实令人困惑 - 我认为以下示例可能对其他人有帮助。
正如其他人之前所说 - Bitmap 继承自抽象 Image 类
Abstract 实际上意味着您无法创建它的 New() 实例。
但是您可以执行以下操作:
如果执行了以下操作,您现在可以像使用同一个位图对象一样使用 imgGood:
这里的好处是您可以使用 Graphics 绘制 imgGood 对象 object
这里imgGood可以是任何图像对象 - 位图、图元文件或任何其他继承自图像的对象!
This is a clarification because I have seen things done in code which are honestly confusing - I think the following example might assist others.
As others have said before - Bitmap inherits from the Abstract Image class
Abstract effectively means you cannot create a New() instance of it.
But you can do the following:
You can now use imgGood as you would the same bitmap object if you had done the following:
The nice thing here is you can draw the imgGood object using a Graphics object
Here imgGood can be any Image object - Bitmap, Metafile, or anything else that inherits from Image!
Image 提供了对任意图像的抽象访问,它定义了一组可以逻辑地应用于 Image 的任何实现的方法。 它不受任何特定图像格式或实现的限制。 Bitmap是图像抽象类的具体实现,它封装了Windows GDI位图对象。 位图只是 Image 抽象类的一个特定实现,它依赖于 GDI 位图对象。
例如,您可以通过继承 Image 类并实现抽象方法来创建自己的 Image 抽象实现。
不管怎样,这只是 OOP 的一个简单的基本用法,应该不难理解。
Image provides an abstract access to an arbitrary image , it defines a set of methods that can loggically be applied upon any implementation of Image. Its not bounded to any particular image format or implementation . Bitmap is a specific implementation to the image abstract class which encapsulate windows GDI bitmap object. Bitmap is just a specific implementation to the Image abstract class which relay on the GDI bitmap Object.
You could for example , Create your own implementation to the Image abstract , by inheriting from the Image class and implementing the abstract methods.
Anyway , this is just a simple basic use of OOP , it shouldn't be hard to catch.