APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public Class BufferedImage

extends Image
implements WritableRenderedImage, Transparency
Class Inheritance
All Implemented Interfaces
java.awt.Transparency, java.awt.image.WritableRenderedImage, java.awt.image.RenderedImage
Known Direct Subclasses
sun.awt.image.OffScreenImage
Imports
java.awt.Graphics2D, .GraphicsEnvironment, .Point, .Rectangle, .Transparency, java.awt.color.ColorSpace, java.util.Hashtable, .Set, .Vector, sun.awt.image.ByteComponentRaster, .BytePackedRaster, .IntegerComponentRaster, .OffScreenImageSource, .ShortComponentRaster

The BufferedImage 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. All BufferedImage objects have an upper left corner coordinate of (0, 0). Any Raster used to construct a BufferedImage must therefore have minX=0 and minY=0.

This class relies on the data fetching and setting methods of Raster, and on the color characterization methods of ColorModel.

See Also
ColorModel, Raster, WritableRaster

Field Summary

Modifier and TypeField and Description
private ColorModel
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private int
private OffScreenImageSource
private Hashtable<String, Object>
private final WritableRaster
public static final int
TYPE_3BYTE_BGR

Represents an image with 8-bit RGB color components, corresponding to a Windows-style BGR color model) with the colors Blue, Green, and Red stored in 3 bytes.

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.

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.

public static final int
TYPE_BYTE_BINARY

Represents an opaque byte-packed 1, 2, or 4 bit image.

public static final int
TYPE_BYTE_GRAY

Represents a unsigned byte grayscale image, non-indexed.

public static final int
TYPE_BYTE_INDEXED

Represents an indexed byte image.

public static final int
TYPE_CUSTOM

Image type is not recognized so it must be a customized image.

public static final int
TYPE_INT_ARGB

Represents an image with 8-bit RGBA color components packed into integer pixels.

public static final int
TYPE_INT_ARGB_PRE

Represents an image with 8-bit RGBA color components packed into integer pixels.

public static final int
TYPE_INT_BGR

Represents an image with 8-bit RGB color components, corresponding to a Windows- or Solaris- style BGR color model, with the colors Blue, Green, and Red packed into integer pixels.

public static final int
TYPE_INT_RGB

Represents an image with 8-bit RGB color components packed into integer pixels.

public static final int
TYPE_USHORT_555_RGB

Represents an image with 5-5-5 RGB color components (5-bits red, 5-bits green, 5-bits blue) with no alpha.

public static final int
TYPE_USHORT_565_RGB

Represents an image with 5-6-5 RGB color components (5-bits red, 6-bits green, 5-bits blue) with no alpha.

public static final int
TYPE_USHORT_GRAY

Represents an unsigned short grayscale image, non-indexed).

Inherited from java.awt.Image:
accelerationPrioritySCALE_AREA_AVERAGINGSCALE_DEFAULTSCALE_FASTSCALE_REPLICATESCALE_SMOOTHUndefinedProperty

Constructor Summary

AccessConstructor and Description
public
BufferedImage(int
width of the created image
width
,
int
height of the created image
height
,
int
type of the created image
imageType
)

Constructs a BufferedImage of one of the predefined image types.

public
BufferedImage(int
width of the created image
width
,
int
height of the created image
height
,
int
type of the created image
imageType
,
IndexColorModel
IndexColorModel of the created image
cm
)

Constructs a BufferedImage of one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.

public
BufferedImage(ColorModel
ColorModel for the new image
cm
,
WritableRaster
Raster for the image data
raster
,
boolean
if true, the data in the raster has been premultiplied with alpha.
isRasterPremultiplied
,
Hashtable<?, ?>
Hashtable of String/Object pairs.
properties
)

Constructs a new BufferedImage with a specified ColorModel and Raster.

Method Summary

Modifier and TypeMethod and Description
public void
public void
coerceData(boolean
true if the alpha has been premultiplied; false otherwise.
isAlphaPremultiplied
)

Forces the data to match the state specified in the isAlphaPremultiplied variable.

public WritableRaster

Returns:

a reference to the supplied or created WritableRaster.
copyData
(WritableRaster
a WritableRaster to hold the returned part of the image, or null
outRaster
)

Implements java.awt.image.RenderedImage.copyData.

Computes an arbitrary rectangular region of the BufferedImage and copies it into a specified WritableRaster.

public Graphics2D

Returns:

a Graphics2D, used for drawing into this image.
createGraphics
()

Creates a Graphics2D, which can be used to draw into this BufferedImage.

public WritableRaster

Returns:

a WritableRaster or null if this BufferedImage has no alpha channel associated with its ColorModel.
getAlphaRaster
()

Returns a WritableRaster representing the alpha channel for BufferedImage objects with ColorModel objects that support a separate spatial alpha channel, such as ComponentColorModel and DirectColorModel.

public ColorModel

Returns:

the ColorModel of this BufferedImage.
getColorModel
()

Implements java.awt.image.RenderedImage.getColorModel.

Returns the ColorModel.

public Raster

Returns:

a Raster that is a copy of the image data.
getData
()

Implements java.awt.image.RenderedImage.getData.

Returns the image as one large tile.

public Raster

Returns:

a Raster that is a copy of the image data of the specified region of the BufferedImage
getData
(Rectangle
the region of the BufferedImage to be returned.
rect
)

Implements java.awt.image.RenderedImage.getData.

Computes and returns an arbitrary region of the BufferedImage.

public Graphics

Returns:

a Graphics2D, which can be used to draw into this image.
getGraphics
()

Implements abstract java.awt.Image.getGraphics.

This method returns a Graphics2D, but is here for backwards compatibility.

public int

Returns:

the height of this BufferedImage
getHeight
()

Implements java.awt.image.RenderedImage.getHeight.

Returns the height of the BufferedImage.

public int

Returns:

the height of this BufferedImage
getHeight
(ImageObserver
ignored
observer
)

Implements abstract java.awt.Image.getHeight.

Returns the height of the BufferedImage.

public int

Returns:

the minimum tile index in the x direction.
getMinTileX
()

Implements java.awt.image.RenderedImage.getMinTileX.

Returns the minimum tile index in the x direction.

public int

Returns:

the minimum tile index in the y direction.
getMinTileY
()

Implements java.awt.image.RenderedImage.getMinTileY.

Returns the minimum tile index in the y direction.

public int

Returns:

the minimum x coordinate of this BufferedImage.
getMinX
()

Implements java.awt.image.RenderedImage.getMinX.

Returns the minimum x coordinate of this BufferedImage.

public int

Returns:

the minimum y coordinate of this BufferedImage.
getMinY
()

Implements java.awt.image.RenderedImage.getMinY.

Returns the minimum y coordinate of this BufferedImage.

public int

Returns:

the number of tiles in the x direction.
getNumXTiles
()

Implements java.awt.image.RenderedImage.getNumXTiles.

Returns the number of tiles in the x direction.

public int

Returns:

the number of tiles in the y direction.
getNumYTiles
()

Implements java.awt.image.RenderedImage.getNumYTiles.

Returns the number of tiles in the y direction.

public Object

Returns:

an Object that is the property referred to by the specified name or null if the properties of this image are not yet known.
getProperty
(String
the property name
name
,
ImageObserver
the ImageObserver that receives notification regarding image information
observer
)

Implements abstract java.awt.Image.getProperty.

Returns a property of the image by name.

public Object

Returns:

an Object that is the property referred to by the specified name.
getProperty
(String
the property name
name
)

Implements java.awt.image.RenderedImage.getProperty.

Returns a property of the image by name.

public String[]

Returns:

a String array containing all of the property names that getProperty(String) recognizes; or null if no property names are recognized.
getPropertyNames
()

Implements java.awt.image.RenderedImage.getPropertyNames.

Returns an array of names recognized by getProperty(String) or null, if no property names are recognized.

public WritableRaster

Returns:

the WritableRaster of this BufferedImage.
getRaster
()

Returns the WritableRaster.

public int

Returns:

an integer pixel in the default RGB color model and default sRGB colorspace.
getRGB
(int
the X coordinate of the pixel from which to get the pixel in the default RGB color model and sRGB color space
x
,
int
the Y coordinate of the pixel from which to get the pixel in the default RGB color model and sRGB color space
y
)

Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.

public int[]

Returns:

array of RGB pixels.
getRGB
(int
the starting X coordinate
startX
,
int
the starting Y coordinate
startY
,
int
width of region
w
,
int
height of region
h
,
int[]
if not null, the rgb pixels are written here
rgbArray
,
int
offset into the rgbArray
offset
,
int
scanline stride for the rgbArray
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.

public SampleModel

Returns:

the SampleModel of this BufferedImage.
getSampleModel
()

Implements java.awt.image.RenderedImage.getSampleModel.

Returns the SampleModel associated with this BufferedImage.

public ImageProducer

Returns:

the ImageProducer that is used to produce the pixels for this image.
getSource
()

Implements abstract java.awt.Image.getSource.

Returns the object that produces the pixels for the image.

public Vector<RenderedImage>

Returns:

a Vector containing immediate sources of this BufferedImage object's image date, or null if this BufferedImage has no information about its immediate sources, or an empty Vector if this BufferedImage has no immediate sources.
getSources
()

Implements java.awt.image.RenderedImage.getSources.

Returns a Vector of RenderedImage objects that are the immediate sources, not the sources of these immediate sources, of image data for this BufferedImage.

public BufferedImage

Returns:

a BufferedImage that is the subimage of this BufferedImage.
getSubimage
(int
the X coordinate of the upper-left corner of the specified rectangular region
x
,
int
the Y coordinate of the upper-left corner of the specified rectangular region
y
,
int
the width of the specified rectangular region
w
,
int
the height of the specified rectangular region
h
)

Returns a subimage defined by a specified rectangular region.

public Raster

Returns:

a Raster that is the tile defined by the arguments tileX and tileY.
getTile
(int
the x index of the requested tile in the tile array
tileX
,
int
the y index of the requested tile in the tile array
tileY
)

Implements java.awt.image.RenderedImage.getTile.

Returns tile (tileX, tileY).

public int

Returns:

the x offset of the tile grid.
getTileGridXOffset
()

Implements java.awt.image.RenderedImage.getTileGridXOffset.

Returns the x offset of the tile grid relative to the origin, For example, the x coordinate of the location of tile (0, 0).

public int

Returns:

the y offset of the tile grid.
getTileGridYOffset
()

Implements java.awt.image.RenderedImage.getTileGridYOffset.

Returns the y offset of the tile grid relative to the origin, For example, the y coordinate of the location of tile (0, 0).

public int

Returns:

the tile height in pixels.
getTileHeight
()

Implements java.awt.image.RenderedImage.getTileHeight.

Returns the tile height in pixels.

public int

Returns:

the tile width in pixels.
getTileWidth
()

Implements java.awt.image.RenderedImage.getTileWidth.

Returns the tile width in pixels.

public int

Returns:

the transparency of this BufferedImage.
getTransparency
()

Implements java.awt.Transparency.getTransparency.

Returns the transparency.

public int

Returns:

the image type of this BufferedImage.
getType
()

Returns the image type.

public int

Returns:

the width of this BufferedImage
getWidth
()

Implements java.awt.image.RenderedImage.getWidth.

Returns the width of the BufferedImage.

public int

Returns:

the width of this BufferedImage
getWidth
(ImageObserver
ignored
observer
)

Implements abstract java.awt.Image.getWidth.

Returns the width of the BufferedImage.

public WritableRaster

Returns:

a WritableRaster that is the tile, indicated by the specified indices, to be checked out for writing.
getWritableTile
(int
the x index of the tile
tileX
,
int
the y index of the tile
tileY
)

Implements java.awt.image.WritableRenderedImage.getWritableTile.

Checks out a tile for writing.

public Point[]

Returns:

a Point array that indicates the tiles that are checked out for writing, or null if no tiles are checked out for writing.
getWritableTileIndices
()

Implements java.awt.image.WritableRenderedImage.getWritableTileIndices.

Returns an array of Point objects indicating which tiles are checked out for writing.

public boolean

Returns:

true if any tile is checked out for writing; false otherwise.
hasTileWriters
()

Implements java.awt.image.WritableRenderedImage.hasTileWriters.

Returns whether or not any tile is checked out for writing.

private static native void
public boolean

Returns:

true if the alpha has been premultiplied; false otherwise.
isAlphaPremultiplied
()

Returns whether or not the alpha has been premultiplied.

private static boolean
public boolean

Returns:

true if the tile specified by the specified indices is checked out for writing; false otherwise.
isTileWritable
(int
the x index of the tile.
tileX
,
int
the y index of the tile.
tileY
)

Implements java.awt.image.WritableRenderedImage.isTileWritable.

Returns whether or not a tile is currently checked out for writing.

public void
releaseWritableTile(int
the x index of the tile
tileX
,
int
the y index of the tile
tileY
)

Implements java.awt.image.WritableRenderedImage.releaseWritableTile.

Relinquishes permission to write to a tile.

public void
removeTileObserver(TileObserver
the specified TileObserver.
to
)

Implements java.awt.image.WritableRenderedImage.removeTileObserver.

Removes a tile observer.

public void
setData(Raster
the specified Raster
r
)

Implements java.awt.image.WritableRenderedImage.setData.

Sets a rectangular region of the image to the contents of the specified Raster r, which is assumed to be in the same coordinate space as the BufferedImage.

public void
setRGB(int
the X coordinate of the pixel to set
x
,
int
the Y coordinate of the pixel to set
y
,
int
the RGB value
rgb
)

Sets a pixel in this BufferedImage to the specified RGB value.

public void
setRGB(int
the starting X coordinate
startX
,
int
the starting Y coordinate
startY
,
int
width of the region
w
,
int
height of the region
h
,
int[]
the rgb pixels
rgbArray
,
int
offset into the rgbArray
offset
,
int
scanline stride for the rgbArray
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.

public String

Returns:

a String representing this BufferedImage.
toString
()

Overrides java.lang.Object.toString.

Returns a String representation of this BufferedImage object and its values.

Inherited from java.awt.Image:
flushgetAccelerationPrioritygetCapabilitiesgetScaledInstancesetAccelerationPriority