Spec-Zone .ru
спецификации, руководства, описания, API
|
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Image | +--java.awt.image.BufferedImage
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.
ColorModel
,
Raster
,
WritableRaster
Field Summary | |
static 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. |
static 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. |
static 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. |
static int |
TYPE_BYTE_BINARY
Represents an opaque byte-packed binary image. |
static int |
TYPE_BYTE_GRAY
Represents a unsigned byte grayscale image, non-indexed. |
static int |
TYPE_BYTE_INDEXED
Represents an indexed byte image. |
static int |
TYPE_CUSTOM
Image type is not recognized so it must be a customized image. |
static int |
TYPE_INT_ARGB
Represents an image with 8-bit RGBA color components packed into integer pixels. |
static int |
TYPE_INT_ARGB_PRE
Represents an image with 8-bit RGBA color components packed into integer pixels. |
static 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. |
static int |
TYPE_INT_RGB
Represents an image with 8-bit RGB color components packed into integer pixels. |
static 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. |
static 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. |
static int |
TYPE_USHORT_GRAY
Represents an unsigned short grayscale image, non-indexed). |
Fields inherited from class java.awt.Image |
SCALE_AREA_AVERAGING,
SCALE_DEFAULT,
SCALE_FAST,
SCALE_REPLICATE,
SCALE_SMOOTH,
UndefinedProperty |
Constructor Summary | |
BufferedImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
Constructs a new BufferedImage with a specified
ColorModel and Raster . |
|
BufferedImage(int width,
int height,
int imageType)
Constructs a BufferedImage of one of the predefined
image types. |
|
BufferedImage(int width,
int height,
int imageType,
IndexColorModel cm)
Constructs a BufferedImage of one of the predefined
image types:
TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED |
Method Summary | |
void |
addTileObserver(TileObserver to)
Adds a tile observer. |
void |
coerceData(boolean isAlphaPremultiplied)
Forces the data to match the state specified in the isAlphaPremultiplied variable. |
WritableRaster |
copyData(WritableRaster outRaster)
Computes an arbitrary rectangular region of the BufferedImage and copies it into a specified
WritableRaster . |
Graphics2D |
createGraphics()
Creates a Graphics2D , which can be used to draw into
this BufferedImage . |
void |
flush()
Flushes all resources being used to cache optimization information. |
WritableRaster |
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 . |
ColorModel |
getColorModel()
Returns the ColorModel . |
Raster |
getData()
Returns the image as one large tile. |
Raster |
getData(Rectangle rect)
Computes and returns an arbitrary region of the BufferedImage . |
Graphics |
getGraphics()
This method returns a Graphics2D , but is here
for backwards compatibility. |
int |
getHeight()
Returns the height of the BufferedImage . |
int |
getHeight(ImageObserver observer)
Returns the actual height of the image. |
int |
getMinTileX()
Returns the minimum tile index in the x direction. |
int |
getMinTileY()
Returns the minimum tile index in the y direction. |
int |
getMinX()
Returns the minimum x coordinate of this BufferedImage . |
int |
getMinY()
Returns the minimum y coordinate of this BufferedImage . |
int |
getNumXTiles()
Returns the number of tiles in the x direction. |
int |
getNumYTiles()
Returns the number of tiles in the y direction. |
Object |
getProperty(String name)
Returns a property of the image by name. |
Object |
getProperty(String name,
ImageObserver observer)
Returns a property of the image by name. |
String[] |
getPropertyNames()
Returns an array of names recognized by getProperty(String)
or null , if no property names are recognized. |
WritableRaster |
getRaster()
Returns the WritableRaster . |
int |
getRGB(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. |
SampleModel |
getSampleModel()
Returns the SampleModel associated with this
BufferedImage . |
ImageProducer |
getSource()
Returns the object that produces the pixels for the image. |
Vector |
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 . |
BufferedImage |
getSubimage(int x,
int y,
int w,
int h)
Returns a subimage defined by a specified rectangular region. |
Raster |
getTile(int tileX,
int tileY)
Returns tile ( tileX , tileY ). |
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). |
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). |
int |
getTileHeight()
Returns the tile height in pixels. |
int |
getTileWidth()
Returns the tile width in pixels. |
int |
getType()
Returns the image type. |
int |
getWidth()
Returns the width of the BufferedImage . |
int |
getWidth(ImageObserver observer)
Returns the actual width of the image. |
WritableRaster |
getWritableTile(int tileX,
int tileY)
Checks out a tile for writing. |
Point[] |
getWritableTileIndices()
Returns an array of Point objects indicating which tiles
are checked out for writing. |
boolean |
hasTileWriters()
Returns whether or not any tile is checked out for writing. |
boolean |
isAlphaPremultiplied()
Returns whether or not the alpha has been premultiplied. |
boolean |
isTileWritable(int tileX,
int tileY)
Returns whether or not a tile is currently checked out for writing. |
void |
releaseWritableTile(int tileX,
int tileY)
Relinquishes permission to write to a tile. |
void |
removeTileObserver(TileObserver to)
Removes a tile observer. |
void |
setData(Raster r)
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 . |
void |
setRGB(int x,
int y,
int rgb)
Sets a pixel in this BufferedImage to the specified
RGB value. |
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. |
String |
toString()
Returns a String representation of this
BufferedImage object and its values. |
Methods inherited from class java.awt.Image |
getScaledInstance |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int TYPE_CUSTOM
public static final int TYPE_INT_RGB
DirectColorModel
without
alpha.public static final int TYPE_INT_ARGB
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 created image created is consistent with images
created in the JDK1.1 and earlier releases.public static final int TYPE_INT_ARGB_PRE
DirectColorModel
with alpha. The color data in this image is considered to be
premultiplied with alpha.public static final int TYPE_INT_BGR
ComponentColorModel
.public static final int TYPE_3BYTE_BGR
ComponentColorModel
.public static final int TYPE_4BYTE_ABGR
ComponentColorModel
with 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.public static final int TYPE_4BYTE_ABGR_PRE
ComponentColorModel
with 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.public static final int TYPE_USHORT_565_RGB
DirectColorModel
.public static final int TYPE_USHORT_555_RGB
DirectColorModel
.public static final int TYPE_BYTE_GRAY
ComponentColorModel
with a CS_GRAY
ColorSpace
.public static final int TYPE_USHORT_GRAY
ComponentColorModel
with a CS_GRAY
ColorSpace
.public static final int TYPE_BYTE_BINARY
IndexColorModel
without alpha. When this
type is used as the imageType
argument to the
BufferedImage
constructor that takes an
imageType
argument but no ColorModel
argument, an IndexColorModel
is created with
two colors in the default sRGB ColorSpace
:
{0, 0, 0} and {255, 255, 255}.public static final int TYPE_BYTE_INDEXED
imageType
argument to the BufferedImage
constructor that takes an imageType
argument
but no ColorModel
argument, an
IndexColorModel
is 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.Constructor Detail |
public BufferedImage(int width, int height, int imageType)
BufferedImage
of one of the predefined
image types. The ColorSpace
for the image is the
default sRGB space.width
- width of the created imageheight
- height of the created imageimageType
- type of the created imageColorSpace
,
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
public BufferedImage(int width, int height, int imageType, IndexColorModel cm)
BufferedImage
of one of the predefined
image types:
TYPE_BYTE_BINARY or TYPE_BYTE_INDEXEDwidth
- width of the created imageheight
- height of the created imageimageType
- type of the created imagecm
- IndexColorModel
of the created imageTYPE_BYTE_BINARY
,
TYPE_BYTE_INDEXED
public BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties)
BufferedImage
with a specified
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, a RasterFormatException
is thrown. This
method can multiply or divide the color Raster
data by
alpha to match the alphaPremultiplied
state
in the ColorModel
. Properties for this
BufferedImage
can be established by passing
in a Hashtable
of String
/Object
pairs.ColorModel
- ColorModel
for the new imageraster
- Raster
for the image dataisRasterPremultiplied
- if true
, the data in
the raster has been premultiplied with alpha.properties
- Hashtable
of
String
/Object
pairs.RasterFormatException
- 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.IllegalArgumentException
- if
raster
is incompatible with cm
ColorModel
,
Raster
,
WritableRaster
Method Detail |
public int getType()
BufferedImage
.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
public ColorModel getColorModel()
ColorModel
.ColorModel
of this
BufferedImage
.public WritableRaster getRaster()
WritableRaster
.WriteableRaster
of this
BufferedImage
.public WritableRaster getAlphaRaster()
WritableRaster
representing the alpha
channel for BufferedImage
objects
with ColorModel
objects 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
ColorModel
objects 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
that
has alpha in the lookup table, this method returns
null
since there is no spatially discrete alpha
channel. This method creates a new
WritableRaster
, but shares the data array.WritableRaster
or null
if this
BufferedImage
has no alpha channel associated
with its ColorModel
.public int getRGB(int x, int y)
ColorModel
. There are only 8-bits of
precision for each color component in the returned data when using
this method.x, y
- the coordinates of the pixel from which to get
the pixel in the default RGB color model and sRGB
color spacepublic int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
ColorModel
. 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)];
startX,
- startY the starting coordinatesw
- width of regionh
- height of regionrgbArray
- if not null
, the rgb pixels are
written hereoffset
- offset into the rgbArray
scansize
- scanline stride for the rgbArray
IllegalArgumentException
- if an unknown
datatype is specifiedpublic void setRGB(int x, int y, int rgb)
BufferedImage
to 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 an IndexColorModel
, the index with the nearest
color is chosen.x, y
- the coordinates of the pixel to setrgb
- the RGB valuepublic void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
ColorModel
. 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.
startX, startY
- the starting coordinatesw
- width of the regionh
- height of the regionrgbArray
- the rgb pixelsoffset
- offset into the rgbArray
scansize
- scanline stride for the rgbArray
public int getWidth()
BufferedImage
.BufferedImage
.public int getHeight()
BufferedImage
.BufferedImage
.public int getWidth(ImageObserver observer)
ImageObserver
is notified later and
-1
is returned.observer
- the ImageObserver
that receives
information about the image-1
if the width
is not yet known.Image.getHeight(ImageObserver)
,
ImageObserver
public int getHeight(ImageObserver observer)
ImageObserver
is notified later and
-1
is returned.observer
- the ImageObserver
that receives
information about the image-1
if the height
is not yet known.Image.getWidth(ImageObserver)
,
ImageObserver
public ImageProducer getSource()
ImageProducer
that is used to produce the
pixels for this image.ImageProducer
public Object getProperty(String name, ImageObserver observer)
UndefinedProperty
field. If the properties
for this image are not yet known, then this method returns
null
and the ImageObserver
object 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.name
- the property nameobserver
- the ImageObserver
that receives
notification regarding image informationObject
that is the property referred to by the
specified name
or null
if the
properties of this image are not yet known.ImageObserver
,
Image.UndefinedProperty
public Object getProperty(String name)
name
- the property nameObject
that is the property referred to by
the specified name
.public void flush()
public Graphics getGraphics()
Graphics2D
, but is here
for backwards compatibility. createGraphics
is more
convenient, since it is declared to return a
Graphics2D
.Graphics2D
, which can be used to draw into
this image.public Graphics2D createGraphics()
Graphics2D
, which can be used to draw into
this BufferedImage
.Graphics2D
, used for drawing into this
image.public BufferedImage getSubimage(int x, int y, int w, int h)
BufferedImage
shares the same
data array as the original image.x, y
- the coordinates of the upper-left corner of the
specified rectangular regionw
- the width of the specified rectangular regionh
- the height of the specified rectangular regionBufferedImage
that is the subimage of this
BufferedImage
.RasterFormatException
- if the specified
area is not contained within this BufferedImage
.public boolean isAlphaPremultiplied()
true
if there is no alpha since the
default alpha is OPAQUE.true
if the alpha has been premultiplied;
false
otherwise.public void coerceData(boolean isAlphaPremultiplied)
isAlphaPremultiplied
variable. It may multiply or
divide the color raster data by alpha, or do nothing if the data is
in the correct state.isAlphaPremultiplied
- true
if the alpha has been
premultiplied; false
otherwise.public String toString()
String
representation of this
BufferedImage
object and its values.String
representing this
BufferedImage
.public Vector getSources()
Vector
of RenderedImage
objects that are
the immediate sources, not the sources of these immediate sources,
of image data for this BufferedImage
. This
method returns null
if the BufferedImage
has no information about its immediate sources. It returns an
empty Vector
if the BufferedImage
has no
immediate sources.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.public String[] getPropertyNames()
getProperty(String)
or null
, if no property names are recognized.String
array containing all of the property
names that getProperty(String)
recognizes;
or null
if no property names are recognized.public int getMinX()
BufferedImage
. This is always zero.BufferedImage
.public int getMinY()
BufferedImage
. This is always zero.BufferedImage
.public SampleModel getSampleModel()
SampleModel
associated with this
BufferedImage
.SampleModel
of this
BufferedImage
.public int getNumXTiles()
public int getNumYTiles()
public int getMinTileX()
public int getMinTileY()
public int getTileWidth()
public int getTileHeight()
public int getTileGridXOffset()
public int getTileGridYOffset()
public Raster getTile(int tileX, int tileY)
tileX
, tileY
). Note
that tileX
and tileY
are indices
into the tile array, not pixel locations. The Raster
that is returned is live, which means that it is updated if the
image is changed.tileX
- the x index of the requested tile in the tile arraytileY
- the y index of the requested tile in the tile arrayRaster
that is the tile defined by the
arguments tileX
and tileY
.ArrayIndexOutOfBoundsException
- if both
tileX
and tileY
are not
equal to 0public Raster getData()
Raster
returned is a copy of the image data is not updated if the
image is changed.Raster
that is a copy of the image data.public Raster getData(Rectangle rect)
BufferedImage
. The Raster
returned is a
copy of the image data and is not updated if the image is
changed.rect
- the region of the BufferedImage
to be
returned.Raster
that is a copy of the image data of
the specified region of the BufferedImage
public WritableRaster copyData(WritableRaster outRaster)
BufferedImage
and copies it into a specified
WritableRaster
. The region to be computed is
determined from the bounds of the specified
WritableRaster
. The specified
WritableRaster
must have a
SampleModel
that is compatible with this image. If
outRaster
is null
,
an appropriate WritableRaster
is created.outRaster
- a WritableRaster
to hold the returned
part of the image, or null
WritableRaster
.public void setData(Raster r)
Raster
r
, which is
assumed to be in the same coordinate space as the
BufferedImage
. The operation is clipped to the bounds
of the BufferedImage
.r
- the specified Raster
public void addTileObserver(TileObserver to)
to
- the specified TileObserver
public void removeTileObserver(TileObserver to)
to
- the specified TileObserver
.public boolean isTileWritable(int tileX, int tileY)
tileX
- the x index of the tile.tileY
- the y index of the tile.true
if the tile specified by the specified
indices is checked out for writing; false
otherwise.ArrayIndexOutOfBoundsException
- if both
tileX
and tileY
are not equal
to 0public Point[] getWritableTileIndices()
Point
objects indicating which tiles
are checked out for writing. Returns null
if none are
checked out.Point
array that indicates the tiles that
are checked out for writing, or null
if no
tiles are checked out for writing.public boolean hasTileWriters()
(getWritableTileIndices() != null).
true
if any tile is checked out for writing;
false
otherwise.public WritableRaster getWritableTile(int tileX, int tileY)
TileObservers
are notified when a tile goes from having
no writers to having one writer.tileX
- the x index of the tiletileY
- the y index of the tileWritableRaster
that is the tile, indicated by
the specified indices, to be checked out for writing.public void releaseWritableTile(int tileX, int tileY)
getWritableTile(int, int)
. Any other leads
to undefined results. All registered TileObservers
are notified when a tile goes from having one writer to having no
writers.tileX
- the x index of the tiletileY
- the y index of the tile
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |