Thepreviousexampleisverbosebecauseituses MediaTracker toloadtheimage
before drawing. You can eliminate the image-loading verbosity by using Swing's
ImageIcon class, as demonstrated here:
ImageIcon ii = new ImageIcon("image.png");
BufferedImage bi = new BufferedImage(ii.getIconWidth(),
Graphics2D bg = bi.createGraphics();
bg.drawImage(ii.getImage(), 0, 0, null);
Buffered Image Architecture
You now have enough knowledge to do a lot with buffered images. (I also show you
some other reason), you should also understand buffered image architecture. Consider
Figure 7-28. A buffered image contains a raster and a color model.
raster storeseachpixelintermsof sample values thatprovidecolorlookupinformation.
For an RGB image, three samples are stored for each pixel, whereas four samples are
stored for an ARGB image.
Samplesarestoredina data buffer ,whichconsistsofoneormorearraysofprimitive
or channel .
Associated with the data buffer is a sample model that communicates with the data
buffer to store sample values and retrieve sample values on behalf of the raster.