- All Implemented Interfaces:
RenderedImage,WritableRenderedImage,Transparency
public class BufferedImage extends Image implements WritableRenderedImage, Transparency
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
Fields Modifier and Type Field Description static intTYPE_3BYTE_BGRRepresents 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.static intTYPE_4BYTE_ABGRRepresents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.static intTYPE_4BYTE_ABGR_PRERepresents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.static intTYPE_BYTE_BINARYRepresents an opaque byte-packed 1, 2, or 4 bit image.static intTYPE_BYTE_GRAYRepresents a unsigned byte grayscale image, non-indexed.static intTYPE_BYTE_INDEXEDRepresents an indexed byte image.static intTYPE_CUSTOMImage type is not recognized so it must be a customized image.static intTYPE_INT_ARGBRepresents an image with 8-bit RGBA color components packed into integer pixels.static intTYPE_INT_ARGB_PRERepresents an image with 8-bit RGBA color components packed into integer pixels.static intTYPE_INT_BGRRepresents 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.static intTYPE_INT_RGBRepresents an image with 8-bit RGB color components packed into integer pixels.static intTYPE_USHORT_555_RGBRepresents an image with 5-5-5 RGB color components (5-bits red, 5-bits green, 5-bits blue) with no alpha.static intTYPE_USHORT_565_RGBRepresents an image with 5-6-5 RGB color components (5-bits red, 6-bits green, 5-bits blue) with no alpha.static intTYPE_USHORT_GRAYRepresents an unsigned short grayscale image, non-indexed).Fields declared in class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty -
Constructor Summary
Constructors Constructor Description BufferedImage(int width, int height, int imageType)Constructs aBufferedImageof one of the predefined image types.BufferedImage(int width, int height, int imageType, IndexColorModel cm)Constructs aBufferedImageof one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)Constructs a newBufferedImagewith a specifiedColorModelandRaster. -
Method Summary
Modifier and Type Method Description voidaddTileObserver(TileObserver to)Adds a tile observer.voidcoerceData(boolean isAlphaPremultiplied)Forces the data to match the state specified in theisAlphaPremultipliedvariable.WritableRastercopyData(WritableRaster outRaster)Computes an arbitrary rectangular region of theBufferedImageand copies it into a specifiedWritableRaster.Graphics2DcreateGraphics()Creates aGraphics2D, which can be used to draw into thisBufferedImage.WritableRastergetAlphaRaster()Returns aWritableRasterrepresenting the alpha channel forBufferedImageobjects withColorModelobjects that support a separate spatial alpha channel, such asComponentColorModelandDirectColorModel.ColorModelgetColorModel()Returns theColorModel.RastergetData()Returns the image as one large tile.RastergetData(Rectangle rect)Computes and returns an arbitrary region of theBufferedImage.GraphicsgetGraphics()This method returns aGraphics2D, but is here for backwards compatibility.intgetHeight()Returns the height of theBufferedImage.intgetHeight(ImageObserver observer)Returns the height of theBufferedImage.intgetMinTileX()Returns the minimum tile index in the x direction.intgetMinTileY()Returns the minimum tile index in the y direction.intgetMinX()Returns the minimum x coordinate of thisBufferedImage.intgetMinY()Returns the minimum y coordinate of thisBufferedImage.intgetNumXTiles()Returns the number of tiles in the x direction.intgetNumYTiles()Returns the number of tiles in the y direction.ObjectgetProperty(String name)Returns a property of the image by name.ObjectgetProperty(String name, ImageObserver observer)Returns a property of the image by name.String[]getPropertyNames()Returns an array of names recognized bygetProperty(String)ornull, if no property names are recognized.WritableRastergetRaster()Returns theWritableRaster.intgetRGB(int x, int y)Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.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.SampleModelgetSampleModel()Returns theSampleModelassociated with thisBufferedImage.ImageProducergetSource()Returns the object that produces the pixels for the image.Vector<RenderedImage>getSources()Returns aVectorofRenderedImageobjects that are the immediate sources, not the sources of these immediate sources, of image data for thisBufferedImage.BufferedImagegetSubimage(int x, int y, int w, int h)Returns a subimage defined by a specified rectangular region.RastergetTile(int tileX, int tileY)Returns tile (tileX,tileY).intgetTileGridXOffset()Returns the x offset of the tile grid relative to the origin, For example, the x coordinate of the location of tile (0, 0).intgetTileGridYOffset()Returns the y offset of the tile grid relative to the origin, For example, the y coordinate of the location of tile (0, 0).intgetTileHeight()Returns the tile height in pixels.intgetTileWidth()Returns the tile width in pixels.intgetTransparency()Returns the transparency.intgetType()Returns the image type.intgetWidth()Returns the width of theBufferedImage.intgetWidth(ImageObserver observer)Returns the width of theBufferedImage.WritableRastergetWritableTile(int tileX, int tileY)Checks out a tile for writing.Point[]getWritableTileIndices()Returns an array ofPointobjects indicating which tiles are checked out for writing.booleanhasTileWriters()Returns whether or not any tile is checked out for writing.booleanisAlphaPremultiplied()Returns whether or not the alpha has been premultiplied.booleanisTileWritable(int tileX, int tileY)Returns whether or not a tile is currently checked out for writing.voidreleaseWritableTile(int tileX, int tileY)Relinquishes permission to write to a tile.voidremoveTileObserver(TileObserver to)Removes a tile observer.voidsetData(Raster r)Sets a rectangular region of the image to the contents of the specifiedRaster r, which is assumed to be in the same coordinate space as theBufferedImage.voidsetRGB(int x, int y, int rgb)Sets a pixel in thisBufferedImageto the specified RGB value.voidsetRGB(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.StringtoString()Returns aStringrepresentation of thisBufferedImageobject and its values.Methods declared in class java.awt.Image
flush, getAccelerationPriority, getCapabilities, getScaledInstance, setAccelerationPriority
-
Field Details
-
TYPE_CUSTOM
public static final int TYPE_CUSTOMImage type is not recognized so it must be a customized image. This type is only used as a return value for the getType() method.- See Also:
- Constant Field Values
-
TYPE_INT_RGB
public static final int TYPE_INT_RGBRepresents an image with 8-bit RGB color components packed into integer pixels. The image has aDirectColorModelwithout alpha. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_INT_ARGB
public static final int TYPE_INT_ARGBRepresents an image with 8-bit RGBA color components packed into integer pixels. The image has aDirectColorModelwith alpha. The color data in this image is considered not to be premultiplied with alpha. When this type is used as theimageTypeargument to aBufferedImageconstructor, the created image is consistent with images created in the JDK1.1 and earlier releases.- See Also:
- Constant Field Values
-
TYPE_INT_ARGB_PRE
public static final int TYPE_INT_ARGB_PRERepresents an image with 8-bit RGBA color components packed into integer pixels. The image has aDirectColorModelwith alpha. The color data in this image is considered to be premultiplied with alpha.- See Also:
- Constant Field Values
-
TYPE_INT_BGR
public static final int TYPE_INT_BGRRepresents 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. There is no alpha. The image has aDirectColorModel. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_3BYTE_BGR
public static final int TYPE_3BYTE_BGRRepresents 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. There is no alpha. The image has aComponentColorModel. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_4BYTE_ABGR
public static final int TYPE_4BYTE_ABGRRepresents 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 aComponentColorModelwith alpha. The color data in this image is 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.- See Also:
- Constant Field Values
-
TYPE_4BYTE_ABGR_PRE
public static final int TYPE_4BYTE_ABGR_PRERepresents 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 aComponentColorModelwith alpha. The color data in this image is 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.- See Also:
- Constant Field Values
-
TYPE_USHORT_565_RGB
public static final int TYPE_USHORT_565_RGBRepresents an image with 5-6-5 RGB color components (5-bits red, 6-bits green, 5-bits blue) with no alpha. This image has aDirectColorModel. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_USHORT_555_RGB
public static final int TYPE_USHORT_555_RGBRepresents an image with 5-5-5 RGB color components (5-bits red, 5-bits green, 5-bits blue) with no alpha. This image has aDirectColorModel. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_BYTE_GRAY
public static final int TYPE_BYTE_GRAYRepresents a unsigned byte grayscale image, non-indexed. This image has aComponentColorModelwith a CS_GRAYColorSpace. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_USHORT_GRAY
public static final int TYPE_USHORT_GRAYRepresents an unsigned short grayscale image, non-indexed). This image has aComponentColorModelwith a CS_GRAYColorSpace. When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded, as described in theAlphaCompositedocumentation.- See Also:
- Constant Field Values
-
TYPE_BYTE_BINARY
public static final int TYPE_BYTE_BINARYRepresents an opaque byte-packed 1, 2, or 4 bit image. The image has anIndexColorModelwithout alpha. When this type is used as theimageTypeargument to theBufferedImageconstructor that takes animageTypeargument but noColorModelargument, a 1-bit image is created with anIndexColorModelwith two colors in the default sRGBColorSpace: {0, 0, 0} and {255, 255, 255}.Images with 2 or 4 bits per pixel may be constructed via the
BufferedImageconstructor that takes aColorModelargument by supplying aColorModelwith an appropriate map size.Images with 8 bits per pixel should use the image types
TYPE_BYTE_INDEXEDorTYPE_BYTE_GRAYdepending on theirColorModel.When color data is stored in an image of this type, the closest color in the colormap is determined by the
IndexColorModeland the resulting index is stored. Approximation and loss of alpha or color components can result, depending on the colors in theIndexColorModelcolormap.- See Also:
- Constant Field Values
-
TYPE_BYTE_INDEXED
public static final int TYPE_BYTE_INDEXEDRepresents an indexed byte image. When this type is used as theimageTypeargument to theBufferedImageconstructor that takes animageTypeargument but noColorModelargument, anIndexColorModelis created with a 256-color 6/6/6 color cube palette with the rest of the colors from 216-255 populated by grayscale values in the default sRGB ColorSpace.When color data is stored in an image of this type, the closest color in the colormap is determined by the
IndexColorModeland the resulting index is stored. Approximation and loss of alpha or color components can result, depending on the colors in theIndexColorModelcolormap.- See Also:
- Constant Field Values
-
-
Constructor Details
-
BufferedImage
public BufferedImage(int width, int height, int imageType)Constructs aBufferedImageof one of the predefined image types. TheColorSpacefor the image is the default sRGB space.- Parameters:
width- width of the created imageheight- height of the created imageimageType- 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_USHORT_GRAY,TYPE_BYTE_BINARY,TYPE_BYTE_INDEXED,TYPE_USHORT_565_RGB,TYPE_USHORT_555_RGB
-
BufferedImage
Constructs aBufferedImageof one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.If the image type is TYPE_BYTE_BINARY, the number of entries in the color model is used to determine whether the image should have 1, 2, or 4 bits per pixel. If the color model has 1 or 2 entries, the image will have 1 bit per pixel. If it has 3 or 4 entries, the image with have 2 bits per pixel. If it has between 5 and 16 entries, the image will have 4 bits per pixel. Otherwise, an IllegalArgumentException will be thrown.
- Parameters:
width- width of the created imageheight- height of the created imageimageType- type of the created imagecm-IndexColorModelof the created image- Throws:
IllegalArgumentException- if the imageType is not TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED or if the imageType is TYPE_BYTE_BINARY and the color map has more than 16 entries.- See Also:
TYPE_BYTE_BINARY,TYPE_BYTE_INDEXED
-
BufferedImage
public BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)Constructs a newBufferedImagewith a specifiedColorModelandRaster. If the number and types of bands in theSampleModelof theRasterdo not match the number and types required by theColorModelto represent its color and alpha components, aRasterFormatExceptionis thrown. This method can multiply or divide the colorRasterdata by alpha to match thealphaPremultipliedstate in theColorModel. Properties for thisBufferedImagecan be established by passing in aHashtableofString/Objectpairs.- Parameters:
cm-ColorModelfor the new imageraster-Rasterfor the image dataisRasterPremultiplied- iftrue, the data in the raster has been premultiplied with alpha.properties-HashtableofString/Objectpairs.- Throws:
RasterFormatException- if the number and types of bands in theSampleModelof theRasterdo not match the number and types required by theColorModelto represent its color and alpha components.IllegalArgumentException- ifrasteris incompatible withcm- See Also:
ColorModel,Raster,WritableRaster
-
-
Method Details
-
getType
public int getType()Returns the image type. If it is not one of the known types, TYPE_CUSTOM is returned.- Returns:
- the image type of this
BufferedImage. - See Also:
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_BYTE_BINARY,TYPE_BYTE_INDEXED,TYPE_USHORT_GRAY,TYPE_USHORT_565_RGB,TYPE_USHORT_555_RGB,TYPE_CUSTOM
-
getColorModel
Returns theColorModel.- Specified by:
getColorModelin interfaceRenderedImage- Returns:
- the
ColorModelof thisBufferedImage.
-
getRaster
Returns theWritableRaster.- Returns:
- the
WritableRasterof thisBufferedImage.
-
getAlphaRaster
Returns aWritableRasterrepresenting the alpha channel forBufferedImageobjects withColorModelobjects that support a separate spatial alpha channel, such asComponentColorModelandDirectColorModel. Returnsnullif there is no alpha channel associated with theColorModelin this image. This method assumes that for allColorModelobjects other thanIndexColorModel, if theColorModelsupports alpha, there is a separate alpha channel which is stored as the last band of image data. If the image uses anIndexColorModelthat has alpha in the lookup table, this method returnsnullsince there is no spatially discrete alpha channel. This method creates a newWritableRaster, but shares the data array.- Returns:
- a
WritableRasterornullif thisBufferedImagehas no alpha channel associated with itsColorModel.
-
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 takes place if this default model does not match the imageColorModel. There are only 8-bits of precision for each color component in the returned data when using this method.An
ArrayOutOfBoundsExceptionmay be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.- Parameters:
x- the X coordinate of the pixel from which to get the pixel in the default RGB color model and sRGB color spacey- the Y coordinate of the pixel from which to get the pixel in the default RGB color model and sRGB color space- Returns:
- an integer pixel in the default RGB color model and default sRGB colorspace.
- See Also:
setRGB(int, int, int),setRGB(int, int, int, int, int[], int, int)
-
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 takes place if the default model does not match the imageColorModel. There are only 8-bits of precision for each color component in the returned data when using this method. With a specified coordinate (x, y) in the image, the ARGB pixel can be accessed in this way:pixel = rgbArray[offset + (y-startY)*scansize + (x-startX)];An
ArrayOutOfBoundsExceptionmay be thrown if the region is not in bounds. However, explicit bounds checking is not guaranteed.- Parameters:
startX- the starting X coordinatestartY- the starting Y coordinatew- width of regionh- height of regionrgbArray- if notnull, the rgb pixels are written hereoffset- offset into thergbArrayscansize- scanline stride for thergbArray- Returns:
- array of RGB pixels.
- See Also:
setRGB(int, int, int),setRGB(int, int, int, int, int[], int, int)
-
setRGB
public void setRGB(int x, int y, int rgb)Sets a pixel in thisBufferedImageto the specified RGB value. The pixel is assumed to be in the default RGB color model, TYPE_INT_ARGB, and default sRGB color space. For images with anIndexColorModel, the index with the nearest color is chosen.An
ArrayOutOfBoundsExceptionmay be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed.- Parameters:
x- the X coordinate of the pixel to sety- the Y coordinate of the pixel to setrgb- the RGB value- See Also:
getRGB(int, int),getRGB(int, int, int, int, int[], int, int)
-
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 takes place if the default model does not match the imageColorModel. There are only 8-bits of precision for each color component in the returned data when using this method. With a specified coordinate (x, y) in the this image, the ARGB pixel can be accessed in this way:pixel = rgbArray[offset + (y-startY)*scansize + (x-startX)];WARNING: No dithering takes place.An
ArrayOutOfBoundsExceptionmay be thrown if the region is not in bounds. However, explicit bounds checking is not guaranteed.- Parameters:
startX- the starting X coordinatestartY- the starting Y coordinatew- width of the regionh- height of the regionrgbArray- the rgb pixelsoffset- offset into thergbArrayscansize- scanline stride for thergbArray- See Also:
getRGB(int, int),getRGB(int, int, int, int, int[], int, int)
-
getWidth
public int getWidth()Returns the width of theBufferedImage.- Specified by:
getWidthin interfaceRenderedImage- Returns:
- the width of this
BufferedImage
-
getHeight
public int getHeight()Returns the height of theBufferedImage.- Specified by:
getHeightin interfaceRenderedImage- Returns:
- the height of this
BufferedImage
-
getWidth
Returns the width of theBufferedImage.- Specified by:
getWidthin classImage- Parameters:
observer- ignored- Returns:
- the width of this
BufferedImage - See Also:
Image.getHeight(java.awt.image.ImageObserver),ImageObserver
-
getHeight
Returns the height of theBufferedImage.- Specified by:
getHeightin classImage- Parameters:
observer- ignored- Returns:
- the height of this
BufferedImage - See Also:
Image.getWidth(java.awt.image.ImageObserver),ImageObserver
-
getSource
Returns the object that produces the pixels for the image.- Specified by:
getSourcein classImage- Returns:
- the
ImageProducerthat is used to produce the pixels for this image. - See Also:
ImageProducer
-
getProperty
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 returns theUndefinedPropertyfield. If the properties for this image are not yet known, then this method returnsnulland theImageObserverobject is notified later. The property name "comment" should be used to store an optional comment that can be presented to the user as a description of the image, its source, or its author.- Specified by:
getPropertyin classImage- Parameters:
name- the property nameobserver- theImageObserverthat receives notification regarding image information- Returns:
- an
Objectthat is the property referred to by the specifiednameornullif the properties of this image are not yet known. - Throws:
NullPointerException- if the property name is null.- See Also:
ImageObserver,Image.UndefinedProperty
-
getProperty
Returns a property of the image by name.- Specified by:
getPropertyin interfaceRenderedImage- Parameters:
name- the property name- Returns:
- an
Objectthat is the property referred to by the specifiedname. - Throws:
NullPointerException- if the property name is null.- See Also:
Image.UndefinedProperty
-
getGraphics
This method returns aGraphics2D, but is here for backwards compatibility.createGraphicsis more convenient, since it is declared to return aGraphics2D.- Specified by:
getGraphicsin classImage- Returns:
- a
Graphics2D, which can be used to draw into this image. - See Also:
Graphics,Component.createImage(int, int)
-
createGraphics
Creates aGraphics2D, which can be used to draw into thisBufferedImage.- Returns:
- a
Graphics2D, used for drawing into this image.
-
getSubimage
Returns a subimage defined by a specified rectangular region. The returnedBufferedImageshares the same data array as the original image.- Parameters:
x- the X coordinate of the upper-left corner of the specified rectangular regiony- the Y coordinate of the upper-left corner of the specified rectangular regionw- the width of the specified rectangular regionh- the height of the specified rectangular region- Returns:
- a
BufferedImagethat is the subimage of thisBufferedImage. - Throws:
RasterFormatException- if the specified area is not contained within thisBufferedImage.
-
isAlphaPremultiplied
public boolean isAlphaPremultiplied()Returns whether or not the alpha has been premultiplied. It returnsfalseif there is no alpha.- Returns:
trueif the alpha has been premultiplied;falseotherwise.
-
coerceData
public void coerceData(boolean isAlphaPremultiplied)Forces the data to match the state specified in theisAlphaPremultipliedvariable. It may multiply or divide the color raster data by alpha, or do nothing if the data is in the correct state.- Parameters:
isAlphaPremultiplied-trueif the alpha has been premultiplied;falseotherwise.
-
toString
Returns aStringrepresentation of thisBufferedImageobject and its values. -
getSources
Returns aVectorofRenderedImageobjects that are the immediate sources, not the sources of these immediate sources, of image data for thisBufferedImage. This method returnsnullif theBufferedImagehas no information about its immediate sources. It returns an emptyVectorif theBufferedImagehas no immediate sources.- Specified by:
getSourcesin interfaceRenderedImage- Returns:
- a
Vectorcontaining immediate sources of thisBufferedImageobject's image date, ornullif thisBufferedImagehas no information about its immediate sources, or an emptyVectorif thisBufferedImagehas no immediate sources.
-
getPropertyNames
Returns an array of names recognized bygetProperty(String)ornull, if no property names are recognized.- Specified by:
getPropertyNamesin interfaceRenderedImage- Returns:
- a
Stringarray containing all of the property names thatgetProperty(String)recognizes; ornullif no property names are recognized.
-
getMinX
public int getMinX()Returns the minimum x coordinate of thisBufferedImage. This is always zero.- Specified by:
getMinXin interfaceRenderedImage- Returns:
- the minimum x coordinate of this
BufferedImage.
-
getMinY
public int getMinY()Returns the minimum y coordinate of thisBufferedImage. This is always zero.- Specified by:
getMinYin interfaceRenderedImage- Returns:
- the minimum y coordinate of this
BufferedImage.
-
getSampleModel
Returns theSampleModelassociated with thisBufferedImage.- Specified by:
getSampleModelin interfaceRenderedImage- Returns:
- the
SampleModelof thisBufferedImage.
-
getNumXTiles
public int getNumXTiles()Returns the number of tiles in the x direction. This is always one.- Specified by:
getNumXTilesin interfaceRenderedImage- Returns:
- the number of tiles in the x direction.
-
getNumYTiles
public int getNumYTiles()Returns the number of tiles in the y direction. This is always one.- Specified by:
getNumYTilesin interfaceRenderedImage- Returns:
- the number of tiles in the y direction.
-
getMinTileX
public int getMinTileX()Returns the minimum tile index in the x direction. This is always zero.- Specified by:
getMinTileXin interfaceRenderedImage- Returns:
- the minimum tile index in the x direction.
-
getMinTileY
public int getMinTileY()Returns the minimum tile index in the y direction. This is always zero.- Specified by:
getMinTileYin interfaceRenderedImage- Returns:
- the minimum tile index in the y direction.
-
getTileWidth
public int getTileWidth()Returns the tile width in pixels.- Specified by:
getTileWidthin interfaceRenderedImage- Returns:
- the tile width in pixels.
-
getTileHeight
public int getTileHeight()Returns the tile height in pixels.- Specified by:
getTileHeightin interfaceRenderedImage- Returns:
- the tile height in pixels.
-
getTileGridXOffset
public int 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). This is always zero.- Specified by:
getTileGridXOffsetin interfaceRenderedImage- Returns:
- the x offset of the tile grid.
-
getTileGridYOffset
public int 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). This is always zero.- Specified by:
getTileGridYOffsetin interfaceRenderedImage- Returns:
- the y offset of the tile grid.
-
getTile
Returns tile (tileX,tileY). Note thattileXandtileYare indices into the tile array, not pixel locations. TheRasterthat is returned is live, which means that it is updated if the image is changed.- Specified by:
getTilein interfaceRenderedImage- Parameters:
tileX- the x index of the requested tile in the tile arraytileY- the y index of the requested tile in the tile array- Returns:
- a
Rasterthat is the tile defined by the argumentstileXandtileY. - Throws:
ArrayIndexOutOfBoundsException- if bothtileXandtileYare not equal to 0
-
getData
Returns the image as one large tile. TheRasterreturned is a copy of the image data is not updated if the image is changed.- Specified by:
getDatain interfaceRenderedImage- Returns:
- a
Rasterthat is a copy of the image data. - See Also:
setData(Raster)
-
getData
Computes and returns an arbitrary region of theBufferedImage. TheRasterreturned is a copy of the image data and is not updated if the image is changed.- Specified by:
getDatain interfaceRenderedImage- Parameters:
rect- the region of theBufferedImageto be returned.- Returns:
- a
Rasterthat is a copy of the image data of the specified region of theBufferedImage - See Also:
setData(Raster)
-
copyData
Computes an arbitrary rectangular region of theBufferedImageand copies it into a specifiedWritableRaster. The region to be computed is determined from the bounds of the specifiedWritableRaster. The specifiedWritableRastermust have aSampleModelthat is compatible with this image. IfoutRasterisnull, an appropriateWritableRasteris created.- Specified by:
copyDatain interfaceRenderedImage- Parameters:
outRaster- aWritableRasterto hold the returned part of the image, ornull- Returns:
- a reference to the supplied or created
WritableRaster.
-
setData
Sets a rectangular region of the image to the contents of the specifiedRaster r, which is assumed to be in the same coordinate space as theBufferedImage. The operation is clipped to the bounds of theBufferedImage.- Specified by:
setDatain interfaceWritableRenderedImage- Parameters:
r- the specifiedRaster- See Also:
getData(),getData(Rectangle)
-
addTileObserver
Adds a tile observer. If the observer is already present, it receives multiple notifications.- Specified by:
addTileObserverin interfaceWritableRenderedImage- Parameters:
to- the specifiedTileObserver
-
removeTileObserver
Removes a tile observer. If the observer was not registered, nothing happens. If the observer was registered for multiple notifications, it is now registered for one fewer notification.- Specified by:
removeTileObserverin interfaceWritableRenderedImage- Parameters:
to- the specifiedTileObserver.
-
isTileWritable
public boolean isTileWritable(int tileX, int tileY)Returns whether or not a tile is currently checked out for writing.- Specified by:
isTileWritablein interfaceWritableRenderedImage- Parameters:
tileX- the x index of the tile.tileY- the y index of the tile.- Returns:
trueif the tile specified by the specified indices is checked out for writing;falseotherwise.- Throws:
ArrayIndexOutOfBoundsException- if bothtileXandtileYare not equal to 0
-
getWritableTileIndices
Returns an array ofPointobjects indicating which tiles are checked out for writing. Returnsnullif none are checked out.- Specified by:
getWritableTileIndicesin interfaceWritableRenderedImage- Returns:
- a
Pointarray that indicates the tiles that are checked out for writing, ornullif no tiles are checked out for writing.
-
hasTileWriters
public boolean hasTileWriters()Returns whether or not any tile is checked out for writing. Semantically equivalent to(getWritableTileIndices() != null).
- Specified by:
hasTileWritersin interfaceWritableRenderedImage- Returns:
trueif any tile is checked out for writing;falseotherwise.
-
getWritableTile
Checks out a tile for writing. All registeredTileObserversare notified when a tile goes from having no writers to having one writer.- Specified by:
getWritableTilein interfaceWritableRenderedImage- Parameters:
tileX- the x index of the tiletileY- the y index of the tile- Returns:
- a
WritableRasterthat is the tile, indicated by the specified indices, to be checked out for writing.
-
releaseWritableTile
public void releaseWritableTile(int tileX, int tileY)Relinquishes permission to write to a tile. If the caller continues to write to the tile, the results are undefined. Calls to this method should only appear in matching pairs with calls togetWritableTile(int, int). Any other leads to undefined results. All registeredTileObserversare notified when a tile goes from having one writer to having no writers.- Specified by:
releaseWritableTilein interfaceWritableRenderedImage- Parameters:
tileX- the x index of the tiletileY- the y index of the tile
-
getTransparency
public int getTransparency()Returns the transparency. Returns either OPAQUE, BITMASK, or TRANSLUCENT.- Specified by:
getTransparencyin interfaceTransparency- Returns:
- the transparency of this
BufferedImage. - Since:
- 1.5
- See Also:
Transparency.OPAQUE,Transparency.BITMASK,Transparency.TRANSLUCENT
-