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
DCM_555_BLU_MASK-
DCM_555_GRN_MASK-
DCM_555_RED_MASK-
DCM_565_BLU_MASK-
DCM_565_GRN_MASK-
DCM_565_RED_MASK-
DCM_ALPHA_MASK-
DCM_BGR_BLU_MASK-
DCM_BGR_GRN_MASK-
DCM_BGR_RED_MASK-
DCM_BLUE_MASK-
DCM_GREEN_MASK-
DCM_RED_MASK-
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.
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.
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.
TYPE_BINARY- Represents an opaque binary image.
TYPE_BYTE_GRAY- Represents a grayscale image (non-indexed).
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.
TYPE_CUSTOM- Image type is not recognized so it must be a customized
image.
TYPE_INT_ARGB- Represents an image with 8-bit RGBA color components packed into
integer pixels.
TYPE_INT_ARGB_PRE- Represents an image with 8-bit RGBA color components packed into
integer pixels.
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.
TYPE_INT_RGB- Represents an image with 8-bit RGB color components packed into
integer pixels.
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.
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.
BufferedImage(ColorModel, WritableRaster, boolean)
- Constructs a new BufferedImage with a given ColorModel
and Raster.
BufferedImage(int, int, int)
- Constructs a BufferedImage of one of the predefined image types.
BufferedImage(int, int, int, IndexColorModel)
- Constructs a BufferedImage of one of the predefined image types:
TYPE_BINARY or TYPE_BYTE_INDEXED
addTileChangeListener(TileChangeListener)
- Forward work to a TileChangeMulticaster.
coerceData(boolean)
- Forces the data to match the state specified in the
isAlphaPremultiplied variable.
createGraphics()
- Creates a Graphics2D, which can be used to draw into this
BufferedImage.
flush()
- Flushes all resources being used to cache optimization information.
getAlphaRaster()
- Returns a Raster representing the alpha channel for BufferedImages
with ColorModels that support a separate spatial alpha channel
(such as ComponentColorModel and DirectColorModel).
getColorModel()
- Returns the ColorModel.
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).
getGraphics()
- This method will actually return a Graphics2D but is here
for backwards compatibility.
Deprecated.
getHeight()
- Returns the height of the BufferedImage.
getHeight(ImageObserver)
- Returns the actual height of the image.
getMaxTileX()
- Return the index of the max tile in the x direction of the image
getMaxTileY()
- Return the index of the max tile in the y direction of the image
getMaxXCoord()
- Return the maximum x coordinate of the rendered image.
getMaxYCoord()
- Return the minimum y coordinate of the rendered image.
getMinTileX()
- Return the index of the min tile in the x direction of the image
getMinTileY()
- Return the index of the min tile in the y direction of the image
getMinXCoord()
- Return the minimum x coordinate of the rendered image.
getMinYCoord()
- Return the minimum y coordinate of the rendered image.
getProperty(String)
- Returns a property of the image by name.
getProperty(String, ImageObserver)
- Returns a property of the image by name.
getPropertyNames()
- Return a list of names recognized by getProperty(String).
getRaster()
- Returns the Raster.
getRect(Rectangle)
- Compute and return an arbitrary region of the RenderedImage.
getRect(WritableRaster)
- Compute an arbitrary rectangular region of the RenderedImage
and copy it into a caller-supplied WritableRaster.
getRGB(int, int)
- Returns an integer pixel in the default RGB color model
(TYPE_INT_ARGB) and default sRGB colorspace.
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.
getSampleModel()
- Return the sample model associated with this image
getSource()
- Returns the object that produces the pixels for the image.
getSources()
- Return a vector of RenderedImages that are the sources of
Image data for this RenderedImage.
getSubimage(int, int, int, int)
- Returns a subimage given a rectangular region.
getTile(int, int)
- Return tile# x, y.
getTileChangeListeners()
- Forward work to a TileChangeMulticaster.
getTileGridXOffset()
- Return the X offset of tile grid relative to the origin
getTileGridYOffset()
- Return the Y offset of tile grid relative to the origin
getTileHeight()
- Return the height of the tile in pixel
getTileWidth()
- Return the width of tile in pixel
getType()
- Returns the image type.
getWidth()
- Returns the width of the BufferedImage.
getWidth(ImageObserver)
- Returns the actual width of the image.
getWritableTile(int, int)
-
getWritableTiles()
- Forward work to a TileChangeMulticaster.
hasTileWriters()
- Forward work to a TileChangeMulticaster.
isAlphaPremultiplied()
- Returns whether or not the alpha has been premultiplied.
isTileWritable(int, int)
- Forward work to a TileChangeMulticaster.
releaseWritableTile(int, int)
-
removeTileChangeListener(TileChangeListener)
- Forward work to a TileChangeMulticaster.
setRect(Raster)
- Set a rect of the image to the contents of rb.
setRGB(int, int, int)
- Set a pixel in a BufferedImage.
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.
tilesAcross()
- Return the number of tiles across the image
tilesDown()
- Return the number of tiles down the image
toString()
- Returns a string representation of the object.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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}.
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.
DCM_RED_MASK
public static final int DCM_RED_MASK
DCM_GREEN_MASK
public static final int DCM_GREEN_MASK
DCM_BLUE_MASK
public static final int DCM_BLUE_MASK
DCM_ALPHA_MASK
public static final int DCM_ALPHA_MASK
DCM_565_RED_MASK
public static final int DCM_565_RED_MASK
DCM_565_GRN_MASK
public static final int DCM_565_GRN_MASK
DCM_565_BLU_MASK
public static final int DCM_565_BLU_MASK
DCM_555_RED_MASK
public static final int DCM_555_RED_MASK
DCM_555_GRN_MASK
public static final int DCM_555_GRN_MASK
DCM_555_BLU_MASK
public static final int DCM_555_BLU_MASK
DCM_BGR_RED_MASK
public static final int DCM_BGR_RED_MASK
DCM_BGR_GRN_MASK
public static final int DCM_BGR_GRN_MASK
DCM_BGR_BLU_MASK
public static final int DCM_BGR_BLU_MASK
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
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
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
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
getColorModel
public ColorModel getColorModel()
- Returns the ColorModel.
getRaster
public WritableRaster getRaster()
- Returns the Raster.
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).
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.
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.
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.
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
getWidth
public int getWidth()
- Returns the width of the BufferedImage.
getHeight
public int getHeight()
- Returns the height of the BufferedImage.
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
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
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
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
getProperty
public Object getProperty(String name)
- Returns a property of the image by name.
flush
public void flush()
- Flushes all resources being used to cache optimization information.
The underlying pixel data is unaffected.
- Overrides:
- flush in class Image
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
createGraphics
public Graphics2D createGraphics()
- Creates a Graphics2D, which can be used to draw into this
BufferedImage.
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.
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.
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.
toString
public String toString()
- Returns a string representation of the object.
- Overrides:
- toString in class Object
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.
getPropertyNames
public String[] getPropertyNames()
- Return a list of names recognized by getProperty(String).
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.
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.
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.
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.
getSampleModel
public SampleModel getSampleModel()
- Return the sample model associated with this image
tilesAcross
public int tilesAcross()
- Return the number of tiles across the image
tilesDown
public int tilesDown()
- Return the number of tiles down the image
getMinTileX
public int getMinTileX()
- Return the index of the min tile in the x direction of the image
getMaxTileX
public int getMaxTileX()
- Return the index of the max tile in the x direction of the image
getMinTileY
public int getMinTileY()
- Return the index of the min tile in the y direction of the image
getMaxTileY
public int getMaxTileY()
- Return the index of the max tile in the y direction of the image
getTileWidth
public int getTileWidth()
- Return the width of tile in pixel
getTileHeight
public int getTileHeight()
- Return the height of the tile in pixel
getTileGridXOffset
public int getTileGridXOffset()
- Return the X offset of tile grid relative to the origin
getTileGridYOffset
public int getTileGridYOffset()
- Return the Y offset of tile grid relative to the origin
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
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.
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.
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.
setRect
public void setRect(Raster rb)
- Set a rect of the image to the contents of rb.
addTileChangeListener
public void addTileChangeListener(TileChangeListener tcl)
- Forward work to a TileChangeMulticaster.
removeTileChangeListener
public void removeTileChangeListener(TileChangeListener tcl)
- Forward work to a TileChangeMulticaster.
getTileChangeListeners
public TileChangeListener[] getTileChangeListeners()
- Forward work to a TileChangeMulticaster.
isTileWritable
public boolean isTileWritable(int tileX,
int tileY)
- Forward work to a TileChangeMulticaster.
getWritableTiles
public Point[] getWritableTiles()
- Forward work to a TileChangeMulticaster.
hasTileWriters
public boolean hasTileWriters()
- Forward work to a TileChangeMulticaster.
getWritableTile
public WritableRaster getWritableTile(int tileX,
int tileY)
releaseWritableTile
public void releaseWritableTile(int tileX,
int tileY)
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature