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
.
BufferedImage
of one of the predefined
image types. The ColorSpace
for the image is the
default sRGB space.BufferedImage
of 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.
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.ReplicateScaleFilter
class.
The Image
object is free to substitute a different filter
that performs the same algorithm yet integrates more efficiently
into the imaging infrastructure supplied by the toolkit.ComponentColorModel
.
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 the
java.awt.AlphaComposite
documentation.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.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.imageType
argument to the
BufferedImage
constructor that takes an
imageType
argument but no ColorModel
argument, a 1-bit image is created with an
IndexColorModel
with two colors in the default
sRGB ColorSpace
: {0, 0, 0} and
{255, 255, 255}.
Images with 2 or 4 bits per pixel may be constructed via
the BufferedImage
constructor that takes a
ColorModel
argument by supplying a
ColorModel
with an appropriate map size.
Images with 8 bits per pixel should use the image types
TYPE_BYTE_INDEXED
or TYPE_BYTE_GRAY
depending on their ColorModel
.
When color data is stored in an image of this type,
the closest color in the colormap is determined
by the IndexColorModel
and the resulting index is stored.
Approximation and loss of alpha or color components
can result, depending on the colors in the
IndexColorModel
colormap.
ComponentColorModel
with a CS_GRAY
ColorSpace
.
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 the
java.awt.AlphaComposite
documentation.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.
When color data is stored in an image of this type,
the closest color in the colormap is determined
by the IndexColorModel
and the resulting index is stored.
Approximation and loss of alpha or color components
can result, depending on the colors in the
IndexColorModel
colormap.
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 is consistent with images
created in the JDK1.1 and earlier releases.DirectColorModel
with alpha. The color data in this image is considered to be
premultiplied with alpha.DirectColorModel
.
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 the
java.awt.AlphaComposite
documentation.DirectColorModel
.
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 the
java.awt.AlphaComposite
documentation.ComponentColorModel
with a CS_GRAY
ColorSpace
.
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 the
java.awt.AlphaComposite
documentation.UndefinedProperty
object should be returned whenever a
property which was not defined for a particular image is fetched.isAlphaPremultiplied
variable. It may multiply or
divide the color raster data by alpha, or do nothing if the data is
in the correct state.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.Graphics2D
, which can be used to draw into
this BufferedImage
.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
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.ColorModel
.Raster
returned is a copy of the image data is not updated if the
image is changed.BufferedImage
. The Raster
returned is a
copy of the image data and is not updated if the image is
changed.Graphics2D
.BufferedImage
.BufferedImage
.BufferedImage
. This is always zero.BufferedImage
. This is always zero.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.null
, if no property names are recognized.ColorModel
. There are only 8-bits of
precision for each color component in the returned data when using
this method.
An ArrayOutOfBoundsException
may be thrown
if the coordinates are not in bounds.
However, explicit bounds checking is not guaranteed.
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)];
An ArrayOutOfBoundsException
may be thrown
if the region is not in bounds.
However, explicit bounds checking is not guaranteed.
SampleModel
associated with this
BufferedImage
.Image
object is returned which will render
the image at the specified width
and
height
by default. The new Image
object
may be loaded asynchronously even if the original source image
has already been loaded completely.
If either width
or height
is a negative number then a value is
substituted to maintain the aspect ratio of the original image
dimensions. If both width
and height
are negative, then the original image dimensions are used.
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.BufferedImage
shares the same
data array as the original image.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.Transparency
.BufferedImage
.BufferedImage
.java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
false
if there is no alpha.wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
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.
An ArrayOutOfBoundsException
may be thrown
if the coordinates are not in bounds.
However, explicit bounds checking is not guaranteed.
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.
An ArrayOutOfBoundsException
may be thrown
if the region is not in bounds.
However, explicit bounds checking is not guaranteed.
String
representation of this
BufferedImage
object and its values.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.