What is the difference between Image and BufferedImage?
As stated in the Oracle Java tutorial for working with Images
• The java.awt.Image class is the superclass that represents graphical images as rectangular arrays of pixels.
• The java.awt.image.BufferedImage class, which extends the Image class to allow the application to operate directly with image data (for example, retrieving or setting up the pixel color). Applications can directly construct instances of this class.
The BufferedImage class is a cornerstone of the Java 2D immediate-mode imaging API. It manages the image in memory and provides methods for storing, interpreting, and obtaining pixel data. Since BufferedImage is a subclass of Image it can be rendered by the Graphics and Graphics2D methods that accept an Image parameter.
A BufferedImage is essentially an Image with an accessible data buffer. It is therefore more efficient to work directly with BufferedImage. A BufferedImage has a ColorModel and a Raster of image data. The ColorModel provides a color interpretation of the image's pixel data.
________________________________________
Can I create a BufferedImage directly from an Image source "image.png"?
Sure.
BufferedImage img = ImageIO.read(getClass().getResource("/path/to/image"));
Partager