java 图像与缓冲图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11810370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image vs. BufferedImage
提问by Jamie
Whenever dealing with the loading and rendering of images in Java, I have previously always used BufferedImage
s to store and manipulate the images in memory.
每当在 Java 中处理图像的加载和渲染时,我以前总是使用BufferedImage
s 在内存中存储和操作图像。
However, I have recently come across a fewdifferentsitesthat use the Image
class instead of BufferedImage
and this got me wondering - what are the differences?
但是,我最近遇到了一些使用该类而不是该类的不同站点,这让我想知道 - 有什么区别?Image
BufferedImage
I'm aware that a BufferedImage
has a larger/optimised toolset, but does come at any cost? If so, when does this cost become noticeable? In which situations would you use an Image
over a BufferedImage
, or vice-versa?
我知道 aBufferedImage
有一个更大/优化的工具集,但不惜一切代价吗?如果是这样,这个成本什么时候变得明显?在什么情况下您会使用Image
over a BufferedImage
,反之亦然?
回答by Petar Minchev
BufferedImage extends Image
. Image
is just a base abstract class and you can't instantiate it. Under the hood you are using BufferedImage
or another implementation for sure.
BufferedImage extends Image
. Image
只是一个基本的抽象类,你不能实例化它。在您正在使用的引擎盖下BufferedImage
或肯定的其他实现。
回答by edwga
There shouldn't be any real performance difference between directly creating a BufferedImage and a Toolkit image (java.awt.Toolkit or Image#getScaledInstance). You'll never have an actual instance of Image because it's an abstract class; you'll only be dealing with its subclasses (e.g. BufferedImage).
直接创建 BufferedImage 和 Toolkit 图像(java.awt.Toolkit 或 Image#getScaledInstance)之间不应该有任何真正的性能差异。你永远不会有 Image 的实际实例,因为它是一个抽象类;您将只处理它的子类(例如 BufferedImage)。