Jamie
Jamie

Reputation: 4078

Image vs. BufferedImage

Whenever dealing with the loading and rendering of images in Java, I have previously always used BufferedImages to store and manipulate the images in memory.

However, I have recently come across a few different sites that use the Image class instead of BufferedImage and this got me wondering - what are the differences?

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?

Upvotes: 20

Views: 17673

Answers (2)

Petar Minchev
Petar Minchev

Reputation: 47403

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.

Upvotes: 23

edwga
edwga

Reputation: 190

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).

Upvotes: 2

Related Questions