posted 19 years ago
Here's the 25¢ tour of BufferedImage:
A BufferedImage is a ColorModel plus a WriteableRaster.The job of the ColorModel is to translate between pixel values and color components. A ColorModel has a ColorSpace. A ColorSpace defines a space of colors, for example the space of gray colors.A WriteableRaster is a SampleModel plus a DataBuffer. Its job is to hold the pixels values of the image.The SampleModel is usually behind the scenes (notice it doesn't get mentioned in my demo). Its job is to set and get pixels from the DataBuffer, since the DataBuffer doesn't know the dimensions of the image, or how many samples there are per pixel.A DataBuffer is just a thin wrapper around one array (usually) of primitive type. One thing to realize about representing images is that their data is stored in a one-dimensional array, rather that in a two-dimensional array of arrays, because a single array affords a better memory layout.
Here's a demo where I:
(1) create an image from a byte[]
(2) extract that byte[] from the image
(3) create a new byte[] based on (2)
(4) do (1) again, and
(5) show the two resulting images.
There is no emoticon for what I am feeling!