All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.awt.image.BufferedImage

java.lang.Object
    |
    +----java.awt.Image
            |
            +----java.awt.image.BufferedImage

public class BufferedImage
extends Image
implements WritableRenderedImage
This subclass describes an Image with an accessible buffer of image data. A BufferedImage is comprised of a ColorModel and a Raster of image data. The number and types of bands in the SampleModel of the Raster must match the number and types required by the ColorModel to represent its color and alpha components.

See Also:
ColorModel, Raster, WritableRaster

Variable Index

 o DCM_555_BLU_MASK
 o DCM_555_GRN_MASK
 o DCM_555_RED_MASK
 o DCM_565_BLU_MASK
 o DCM_565_GRN_MASK
 o DCM_565_RED_MASK
 o DCM_ALPHA_MASK
 o DCM_BGR_BLU_MASK
 o DCM_BGR_GRN_MASK
 o DCM_BGR_RED_MASK
 o DCM_BLUE_MASK
 o DCM_GREEN_MASK
 o DCM_RED_MASK
 o TYPE_3BYTE_BGR
Represents an image with 8-bit RGB color components (corresponds to a Windows-style BGR color model) with the colors Blue, Green, and Red stored in 3 bytes.
 o TYPE_4BYTE_ABGR
Represents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.
 o TYPE_4BYTE_ABGR_PRE
Represents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.
 o TYPE_BINARY
Represents an opaque binary image.
 o TYPE_BYTE_GRAY
Represents a grayscale image (non-indexed).
 o TYPE_BYTE_INDEXED
Represents an indexed byte image When this type is used as the imageType argument to the BufferedImage constructor which takes an imageType argument but no ColorModel argument, an IndexColorModel will be created with an 8-bit grayscale ramp in the default sRGB ColorSpace.
 o TYPE_CUSTOM
Image type is not recognized so it must be a customized image.
 o TYPE_INT_ARGB
Represents an image with 8-bit RGBA color components packed into integer pixels.
 o TYPE_INT_ARGB_PRE
Represents an image with 8-bit RGBA color components packed into integer pixels.
 o TYPE_INT_BGR
Represents an image with 8-bit RGB color components (corresponds to a Windows- or Solaris- style BGR color model) with the colors Blue, Green, and Red packed into integer pixels.
 o TYPE_INT_RGB
Represents an image with 8-bit RGB color components packed into integer pixels.
 o TYPE_SHORT_555_RGB
Represents an image with 5-5-5 RGB color components (5-bits red, 5-bits green, 5-bits blue) with no alpha.
 o TYPE_SHORT_565_RGB
Represents an image with 5-6-5 RGB color components (5-bits red, 6-bits green, 5-bits blue) with no alpha.

Constructor Index

 o BufferedImage(ColorModel, WritableRaster, boolean)
Constructs a new BufferedImage with a given ColorModel and Raster.
 o BufferedImage(int, int, int)
Constructs a BufferedImage of one of the predefined image types.
 o BufferedImage(int, int, int, IndexColorModel)
Constructs a BufferedImage of one of the predefined image types: TYPE_BINARY or TYPE_BYTE_INDEXED

Method Index

 o addTileChangeListener(TileChangeListener)
Forward work to a TileChangeMulticaster.
 o coerceData(boolean)
Forces the data to match the state specified in the isAlphaPremultiplied variable.
 o createGraphics()
Creates a Graphics2D, which can be used to draw into this BufferedImage.
 o flush()
Flushes all resources being used to cache optimization information.
 o getAlphaRaster()
Returns a Raster representing the alpha channel for BufferedImages with ColorModels that support a separate spatial alpha channel (such as ComponentColorModel and DirectColorModel).
 o getColorModel()
Returns the ColorModel.
 o getData()
Return the image as one large tile (for tile based images this will require fetching the whole image and copying the image data over).
 o getGraphics()
This method will actually return a Graphics2D but is here for backwards compatibility. Deprecated.
 o getHeight()
Returns the height of the BufferedImage.
 o getHeight(ImageObserver)
Returns the actual height of the image.
 o getMaxTileX()
Return the index of the max tile in the x direction of the image
 o getMaxTileY()
Return the index of the max tile in the y direction of the image
 o getMaxXCoord()
Return the maximum x coordinate of the rendered image.
 o getMaxYCoord()
Return the minimum y coordinate of the rendered image.
 o getMinTileX()
Return the index of the min tile in the x direction of the image
 o getMinTileY()
Return the index of the min tile in the y direction of the image
 o getMinXCoord()
Return the minimum x coordinate of the rendered image.
 o getMinYCoord()
Return the minimum y coordinate of the rendered image.
 o getProperty(String)
Returns a property of the image by name.
 o getProperty(String, ImageObserver)
Returns a property of the image by name.
 o getPropertyNames()
Return a list of names recognized by getProperty(String).
 o getRaster()
Returns the Raster.
 o getRect(Rectangle)
Compute and return an arbitrary region of the RenderedImage.
 o getRect(WritableRaster)
Compute an arbitrary rectangular region of the RenderedImage and copy it into a caller-supplied WritableRaster.
 o getRGB(int, int)
Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.
 o getRGB(int, int, int, int, int[], int, int)
Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data.
 o getSampleModel()
Return the sample model associated with this image
 o getSource()
Returns the object that produces the pixels for the image.
 o getSources()
Return a vector of RenderedImages that are the sources of Image data for this RenderedImage.
 o getSubimage(int, int, int, int)
Returns a subimage given a rectangular region.
 o getTile(int, int)
Return tile# x, y.
 o getTileChangeListeners()
Forward work to a TileChangeMulticaster.
 o getTileGridXOffset()
Return the X offset of tile grid relative to the origin
 o getTileGridYOffset()
Return the Y offset of tile grid relative to the origin
 o getTileHeight()
Return the height of the tile in pixel
 o getTileWidth()
Return the width of tile in pixel
 o getType()
Returns the image type.
 o getWidth()
Returns the width of the BufferedImage.
 o getWidth(ImageObserver)
Returns the actual width of the image.
 o getWritableTile(int, int)
 o getWritableTiles()
Forward work to a TileChangeMulticaster.
 o hasTileWriters()
Forward work to a TileChangeMulticaster.
 o isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied.
 o isTileWritable(int, int)
Forward work to a TileChangeMulticaster.
 o releaseWritableTile(int, int)
 o removeTileChangeListener(TileChangeListener)
Forward work to a TileChangeMulticaster.
 o setRect(Raster)
Set a rect of the image to the contents of rb.
 o setRGB(int, int, int)
Set a pixel in a BufferedImage.
 o setRGB(int, int, int, int, int[], int, int)
Sets an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, into a portion of the image data.
 o tilesAcross()
Return the number of tiles across the image
 o tilesDown()
Return the number of tiles down the image
 o toString()
Returns a string representation of the object.

Variables

 o TYPE_CUSTOM
public static final int TYPE_CUSTOM
Image type is not recognized so it must be a customized image. This type is only used as a return value for the getType() method.

 o TYPE_INT_RGB
public static final int TYPE_INT_RGB
Represents an image with 8-bit RGB color components packed into integer pixels. The image has a DirectColorModel (without alpha).

 o TYPE_INT_ARGB
public static final int TYPE_INT_ARGB
Represents an image with 8-bit RGBA color components packed into integer pixels. The image has a DirectColorModel (with alpha). The color data in this image is considered not to be premultiplied with alpha. When this type is used as the imageType argument to a BufferedImage constructor, the image created will be consistent with images created in the JDK1.1 and earlier releases.

 o TYPE_INT_ARGB_PRE
public static final int TYPE_INT_ARGB_PRE
Represents an image with 8-bit RGBA color components packed into integer pixels. The image has a DirectColorModel (with alpha). The color data in this image is considered to be premultiplied with alpha.

 o TYPE_INT_BGR
public static final int TYPE_INT_BGR
Represents an image with 8-bit RGB color components (corresponds to a Windows- or Solaris- style BGR color model) with the colors Blue, Green, and Red packed into integer pixels. There is no alpha. The image has a ComponentColorModel.

 o TYPE_3BYTE_BGR
public static final int TYPE_3BYTE_BGR
Represents an image with 8-bit RGB color components (corresponds to a Windows-style BGR color model) with the colors Blue, Green, and Red stored in 3 bytes. There is no alpha. The image has a ComponentColorModel.

 o TYPE_4BYTE_ABGR
public static final int TYPE_4BYTE_ABGR
Represents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha. The image has a ComponentColorModel (with alpha). The color data in this image will be considered not to be premultiplied with alpha. The byte data is interleaved in a single byte array in the order A, B, G, R from lower to higher byte addresses within each pixel.

 o TYPE_4BYTE_ABGR_PRE
public static final int TYPE_4BYTE_ABGR_PRE
Represents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha. The image has a ComponentColorModel (with alpha). The color data in this image will be considered to be premultiplied with alpha. The byte data is interleaved in a single byte array in the order A, B, G, R from lower to higher byte addresses within each pixel.

 o TYPE_SHORT_565_RGB
public static final int TYPE_SHORT_565_RGB
Represents an image with 5-6-5 RGB color components (5-bits red, 6-bits green, 5-bits blue) with no alpha. This image has a DirectColorModel.

 o TYPE_SHORT_555_RGB
public static final int TYPE_SHORT_555_RGB
Represents an image with 5-5-5 RGB color components (5-bits red, 5-bits green, 5-bits blue) with no alpha. This image has a DirectColorModel.

 o TYPE_BYTE_GRAY
public static final int TYPE_BYTE_GRAY
Represents a grayscale image (non-indexed). This image has a ComponentColorModel with a CS_GRAY ColorSpace.

 o TYPE_BINARY
public static final int TYPE_BINARY
Represents an opaque binary image. The image has an IndexColorModel (without alpha). When this type is used as the imageType argument to the BufferedImage constructor which takes an imageType argument but no ColorModel argument, an IndexColorModel will be created with two colors in the default sRGB ColorSpace: {0, 0, 0} and {255, 255, 255}.

 o TYPE_BYTE_INDEXED
public static final int TYPE_BYTE_INDEXED
Represents an indexed byte image When this type is used as the imageType argument to the BufferedImage constructor which takes an imageType argument but no ColorModel argument, an IndexColorModel will be created with an 8-bit grayscale ramp in the default sRGB ColorSpace.

 o DCM_RED_MASK
public static final int DCM_RED_MASK
 o DCM_GREEN_MASK
public static final int DCM_GREEN_MASK
 o DCM_BLUE_MASK
public static final int DCM_BLUE_MASK
 o DCM_ALPHA_MASK
public static final int DCM_ALPHA_MASK
 o DCM_565_RED_MASK
public static final int DCM_565_RED_MASK
 o DCM_565_GRN_MASK
public static final int DCM_565_GRN_MASK
 o DCM_565_BLU_MASK
public static final int DCM_565_BLU_MASK
 o DCM_555_RED_MASK
public static final int DCM_555_RED_MASK
 o DCM_555_GRN_MASK
public static final int DCM_555_GRN_MASK
 o DCM_555_BLU_MASK
public static final int DCM_555_BLU_MASK
 o DCM_BGR_RED_MASK
public static final int DCM_BGR_RED_MASK
 o DCM_BGR_GRN_MASK
public static final int DCM_BGR_GRN_MASK
 o DCM_BGR_BLU_MASK
public static final int DCM_BGR_BLU_MASK

Constructors

 o BufferedImage
public BufferedImage(int width,
                     int height,
                     int imageType)
Constructs a BufferedImage of one of the predefined image types. The ColorSpace for the image will be the default sRGB space.

Parameters:
width - Width of the created image.
height - Height of the created image.
imageType - Type of the created image.
See Also:
ColorSpace, TYPE_INT_RGB, TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_BGR, TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE, TYPE_BYTE_GRAY, TYPE_BINARY, TYPE_BYTE_INDEXED, TYPE_SHORT_565_RGB, TYPE_SHORT_555_RGB
 o BufferedImage
public BufferedImage(int width,
                     int height,
                     int imageType,
                     IndexColorModel cm)
Constructs a BufferedImage of one of the predefined image types: TYPE_BINARY or TYPE_BYTE_INDEXED

Parameters:
width - Width of the created image.
height - Height of the created image.
imageType - Type of the created image.
cm - IndexColorModel of the created image.
Throws: IllegalArgumentException
if the imageType is not TYPE_BINARY or TYPE_BYTE_INDEXED
See Also:
TYPE_BINARY, TYPE_BYTE_INDEXED
 o BufferedImage
public BufferedImage(ColorModel cm,
                     WritableRaster raster,
                     boolean isRasterPremultiplied)
Constructs a new BufferedImage with a given ColorModel and Raster. If the number and types of bands in the SampleModel of the Raster do not match the number and types required by the ColorModel to represent its color and alpha components, an exception will be thrown. This method may multiply or divide the color Raster data by alpha to match the alphaPremultiplied state in the ColorModel.

Parameters:
ColorModel - ColorModel for the new image
raster - Raster for the image data
isRasterPremultiplied - If true, the data in the raster has been premultiplied with alpha.
See Also:
ColorModel, Raster, WritableRaster

Methods

 o getType
public int getType()
Returns the image type. If it is not one of the known types, TYPE_CUSTOM is returned.

See Also:
TYPE_INT_RGB, TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE, TYPE_SHORT_565_RGB, TYPE_SHORT_555_RGB, TYPE_BYTE_GRAY, TYPE_BINARY, TYPE_BYTE_INDEXED, TYPE_CUSTOM
 o getColorModel
public ColorModel getColorModel()
Returns the ColorModel.

 o getRaster
public WritableRaster getRaster()
Returns the Raster.

 o getAlphaRaster
public WritableRaster getAlphaRaster()
Returns a Raster representing the alpha channel for BufferedImages with ColorModels that support a separate spatial alpha channel (such as ComponentColorModel and DirectColorModel). Returns null if there is no alpha channel associated with the ColorModel in this image. This method assumes that for all ColorModels other than IndexColorModel, if the ColorModel supports alpha, there is a separate alpha channel which is stored as the last band of image data. If the image uses an IndexColorModel which has alpha in the lookup table, this method will return null since there is no spatially discrete alpha channel. This method will create a new Raster (but will share the data array).

 o getRGB
public int getRGB(int x,
                  int y)
Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. Color conversion will take place if this default model does not match the image ColorModel. There are only 8-bits of precision for each color component in the returned data when using this method.

 o getRGB
public int[] getRGB(int startX,
                    int startY,
                    int w,
                    int h,
                    int[] rgbArray,
                    int offset,
                    int scansize)
Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data. Color conversion will take place if the default model does not match the image ColorModel. There are only 8-bits of precision for each color component in the returned data when using this method. Given a coordinate (x,y) in the image, the ARGB pixel can be accessed using the following:
    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
 

Parameters:
startX - Starting x Coordinate
startY - Starting y Coordinate
w - Width of region
h - Height of region
rgbArray - If non-null, the rgb pixels will be written here
offset - Offset into the rgbArray
scansize - Scanline stride for the rgbArray
Returns:
Array of RGB pixels.
 o setRGB
public void setRGB(int x,
                   int y,
                   int rgb)
Set a pixel in a BufferedImage. The pixel is assumed to be in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space. For images with an IndexColorModel, the index with the nearest color will be chosen.

 o setRGB
public void setRGB(int startX,
                   int startY,
                   int w,
                   int h,
                   int[] rgbArray,
                   int offset,
                   int scansize)
Sets an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, into a portion of the image data. Color conversion will take place if the default model does not match the image ColorModel. There are only 8-bits of precision for each color component in the returned data when using this method. Given a coordinate (x,y) in the image, the ARGB pixel can be accessed using the following:
    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
 
WARNING: No dithering will take place.

Parameters:
startX - Starting x Coordinate
startY - Starting y Coordinate
w - Width of region
h - Height of region
rgbArray - The rgb pixels
offset - Offset into the rgbArray
scansize - Scanline stride for the rgbArray
 o getWidth
public int getWidth()
Returns the width of the BufferedImage.

 o getHeight
public int getHeight()
Returns the height of the BufferedImage.

 o getWidth
public int getWidth(ImageObserver observer)
Returns the actual width of the image. If the width is not known yet, then the ImageObserver will be notified later and -1 will be returned.

Overrides:
getWidth in class Image
See Also:
getHeight, java.awt.ImageObserver
 o getHeight
public int getHeight(ImageObserver observer)
Returns the actual height of the image. If the height is not known yet, then the ImageObserver will be notified later and -1 will be returned.

Overrides:
getHeight in class Image
See Also:
getWidth, ImageObserver
 o getSource
public ImageProducer getSource()
Returns the object that produces the pixels for the image. This returns null.

Overrides:
getSource in class Image
See Also:
ImageProducer
 o getProperty
public Object getProperty(String name,
                          ImageObserver observer)
Returns a property of the image by name. Individual property names are defined by the various image formats. If a property is not defined for a particular image, this method will return the UndefinedProperty object. If the properties for this image are not yet known, then this method will return null and the ImageObserver object will be notified later. The property name "comment" should be used to store an optional comment which can be presented to the user as a description of the image, its source, or its author.

Overrides:
getProperty in class Image
See Also:
ImageObserver, UndefinedProperty
 o getProperty
public Object getProperty(String name)
Returns a property of the image by name.

 o flush
public void flush()
Flushes all resources being used to cache optimization information. The underlying pixel data is unaffected.

Overrides:
flush in class Image
 o getGraphics
public Graphics getGraphics()
Note: getGraphics() is deprecated.

This method will actually return a Graphics2D but is here for backwards compatibility.

Overrides:
getGraphics in class Image
 o createGraphics
public Graphics2D createGraphics()
Creates a Graphics2D, which can be used to draw into this BufferedImage.

 o getSubimage
public BufferedImage getSubimage(int x,
                                 int y,
                                 int w,
                                 int h)
Returns a subimage given a rectangular region. The returned BufferedImage will share the same data array as the original image.

 o isAlphaPremultiplied
public boolean isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied. It will return true if there is no alpha since the default alpha is OPAQUE.

 o coerceData
public void coerceData(boolean isAlphaPremultiplied)
Forces the data to match the state specified in the isAlphaPremultiplied variable. It may multiply or divide the color Raster data by alpha, or do nothing if the data is in the correct state.

 o toString
public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
 o getSources
public Vector getSources()
Return a vector of RenderedImages that are the sources of Image data for this RenderedImage. Note that this method will often return null.

 o getPropertyNames
public String[] getPropertyNames()
Return a list of names recognized by getProperty(String).

 o getMinXCoord
public int getMinXCoord()
Return the minimum x coordinate of the rendered image. For some image with infinite extent, it could be int.MIN_VALUE.

 o getMaxXCoord
public int getMaxXCoord()
Return the maximum x coordinate of the rendered image. For some image with infinite extent, it could be int.MAX_VALUE.

 o getMinYCoord
public int getMinYCoord()
Return the minimum y coordinate of the rendered image. For some image with infinite extent, it could be int.MIN_VALUE.

 o getMaxYCoord
public int getMaxYCoord()
Return the minimum y coordinate of the rendered image. For some image with infinite extent, it could be int.MAX_VALUE.

 o getSampleModel
public SampleModel getSampleModel()
Return the sample model associated with this image

 o tilesAcross
public int tilesAcross()
Return the number of tiles across the image

 o tilesDown
public int tilesDown()
Return the number of tiles down the image

 o getMinTileX
public int getMinTileX()
Return the index of the min tile in the x direction of the image

 o getMaxTileX
public int getMaxTileX()
Return the index of the max tile in the x direction of the image

 o getMinTileY
public int getMinTileY()
Return the index of the min tile in the y direction of the image

 o getMaxTileY
public int getMaxTileY()
Return the index of the max tile in the y direction of the image

 o getTileWidth
public int getTileWidth()
Return the width of tile in pixel

 o getTileHeight
public int getTileHeight()
Return the height of the tile in pixel

 o getTileGridXOffset
public int getTileGridXOffset()
Return the X offset of tile grid relative to the origin

 o getTileGridYOffset
public int getTileGridYOffset()
Return the Y offset of tile grid relative to the origin

 o getTile
public Raster getTile(int x,
                      int y)
Return tile# x, y. Note that x and y are indexes into the tile array not pixel locations. The Raster that is returned is live and will be updated if the image is changed.

Parameters:
x - the x index of the requested tile in the tile array
y - the y index of the requested tile in the tile array
 o getData
public Raster getData()
Return the image as one large tile (for tile based images this will require fetching the whole image and copying the image data over). The Raster returned is semantically a copy.

 o getRect
public Raster getRect(Rectangle rect)
Compute and return an arbitrary region of the RenderedImage. Note that in general this may involve copying image data. The Raster returned is semantically a copy.

Parameters:
rect - the region of the RenderedImage to be returned.
 o getRect
public WritableRaster getRect(WritableRaster outRaster)
Compute an arbitrary rectangular region of the RenderedImage and copy it into a caller-supplied WritableRaster. The region to be computed is determined from the bounds of the supplied WritableRaster. The supplied WritableRaster must have a ColorModel and SampleModel that are compatible with those of this image.

Parameters:
raster - a WritableRaster to hold the returned part of the image.
Returns:
a reference to the supplied WritableRaster.
 o setRect
public void setRect(Raster rb)
Set a rect of the image to the contents of rb.

 o addTileChangeListener
public void addTileChangeListener(TileChangeListener tcl)
Forward work to a TileChangeMulticaster.

 o removeTileChangeListener
public void removeTileChangeListener(TileChangeListener tcl)
Forward work to a TileChangeMulticaster.

 o getTileChangeListeners
public TileChangeListener[] getTileChangeListeners()
Forward work to a TileChangeMulticaster.

 o isTileWritable
public boolean isTileWritable(int tileX,
                              int tileY)
Forward work to a TileChangeMulticaster.

 o getWritableTiles
public Point[] getWritableTiles()
Forward work to a TileChangeMulticaster.

 o hasTileWriters
public boolean hasTileWriters()
Forward work to a TileChangeMulticaster.

 o getWritableTile
public WritableRaster getWritableTile(int tileX,
                                      int tileY)
 o releaseWritableTile
public void releaseWritableTile(int tileX,
                                int tileY)

All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature