BufferedImagepublic class BufferedImage extends Image implements Transparency, WritableRenderedImageThe BufferedImage subclass describes an {@link
java.awt.Image Image} with an accessible buffer of image data.
A BufferedImage is comprised of a {@link ColorModel} and a
{@link Raster} of image data.
The number and types of bands in the {@link 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 . |
Fields Summary |
---|
int | imageType | ColorModel | colorModel | WritableRaster | raster | OffScreenImageSource | osis | Hashtable | properties | boolean | isAlphaPremultiplied | SurfaceManager | surfaceManager | 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. | public static final int | TYPE_INT_RGBRepresents an image with 8-bit RGB color components packed into
integer pixels. The image has a {@link DirectColorModel} without
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 the
{@link java.awt.AlphaComposite} documentation. | public static final int | TYPE_INT_ARGBRepresents 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 created image is consistent with images
created in the JDK1.1 and earlier releases. | public static final int | TYPE_INT_ARGB_PRERepresents 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. | 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 a {@link 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
{@link java.awt.AlphaComposite} documentation. | 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 a
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
{@link java.awt.AlphaComposite} documentation. | 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 a 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_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 a 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_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
a 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
{@link java.awt.AlphaComposite} documentation. | 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
a 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
{@link java.awt.AlphaComposite} documentation. | public static final int | TYPE_BYTE_GRAYRepresents a unsigned byte grayscale image, non-indexed. This
image has a ComponentColorModel with a CS_GRAY
{@link 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
{@link java.awt.AlphaComposite} documentation. | public static final int | TYPE_USHORT_GRAYRepresents an unsigned short grayscale image, non-indexed). This
image has a 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
{@link java.awt.AlphaComposite} documentation. | public static final int | TYPE_BYTE_BINARYRepresents an opaque byte-packed 1, 2, or 4 bit image. The
image has an {@link 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, 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. | public static final int | TYPE_BYTE_INDEXEDRepresents an indexed byte image. 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
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. | private static final int | DCM_RED_MASK | private static final int | DCM_GREEN_MASK | private static final int | DCM_BLUE_MASK | private static final int | DCM_ALPHA_MASK | private static final int | DCM_565_RED_MASK | private static final int | DCM_565_GRN_MASK | private static final int | DCM_565_BLU_MASK | private static final int | DCM_555_RED_MASK | private static final int | DCM_555_GRN_MASK | private static final int | DCM_555_BLU_MASK | private static final int | DCM_BGR_RED_MASK | private static final int | DCM_BGR_GRN_MASK | private static final int | DCM_BGR_BLU_MASK |
Constructors Summary |
---|
public BufferedImage(int width, int height, int imageType)Constructs a BufferedImage of one of the predefined
image types. The ColorSpace for the image is the
default sRGB space.
ColorModel.loadLibraries();
initIDs();
switch (imageType) {
case TYPE_INT_RGB:
{
colorModel = new DirectColorModel(24,
0x00ff0000, // Red
0x0000ff00, // Green
0x000000ff, // Blue
0x0 // Alpha
);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_INT_ARGB:
{
colorModel = ColorModel.getRGBdefault();
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_INT_ARGB_PRE:
{
colorModel = new
DirectColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
32,
0x00ff0000,// Red
0x0000ff00,// Green
0x000000ff,// Blue
0xff000000,// Alpha
true, // Alpha Premultiplied
DataBuffer.TYPE_INT
);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_INT_BGR:
{
colorModel = new DirectColorModel(24,
0x000000ff, // Red
0x0000ff00, // Green
0x00ff0000 // Blue
);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_3BYTE_BGR:
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = {8, 8, 8};
int[] bOffs = {2, 1, 0};
colorModel = new ComponentColorModel(cs, nBits, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height,
width*3, 3,
bOffs, null);
}
break;
case TYPE_4BYTE_ABGR:
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = {8, 8, 8, 8};
int[] bOffs = {3, 2, 1, 0};
colorModel = new ComponentColorModel(cs, nBits, true, false,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height,
width*4, 4,
bOffs, null);
}
break;
case TYPE_4BYTE_ABGR_PRE:
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = {8, 8, 8, 8};
int[] bOffs = {3, 2, 1, 0};
colorModel = new ComponentColorModel(cs, nBits, true, true,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height,
width*4, 4,
bOffs, null);
}
break;
case TYPE_BYTE_GRAY:
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
int[] nBits = {8};
colorModel = new ComponentColorModel(cs, nBits, false, true,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_USHORT_GRAY:
{
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
int[] nBits = {16};
colorModel = new ComponentColorModel(cs, nBits, false, true,
Transparency.OPAQUE,
DataBuffer.TYPE_USHORT);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_BYTE_BINARY:
{
byte[] arr = {(byte)0, (byte)0xff};
colorModel = new IndexColorModel(1, 2, arr, arr, arr);
raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
width, height, 1, 1, null);
}
break;
case TYPE_BYTE_INDEXED:
{
// Create a 6x6x6 color cube
int[] cmap = new int[256];
int i=0;
for (int r=0; r < 256; r += 51) {
for (int g=0; g < 256; g += 51) {
for (int b=0; b < 256; b += 51) {
cmap[i++] = (r<<16)|(g<<8)|b;
}
}
}
// And populate the rest of the cmap with gray values
int grayIncr = 256/(256-i);
// The gray ramp will be between 18 and 252
int gray = grayIncr*3;
for (; i < 256; i++) {
cmap[i] = (gray<<16)|(gray<<8)|gray;
gray += grayIncr;
}
colorModel = new IndexColorModel(8, 256, cmap, 0, false, -1,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height, 1, null);
}
break;
case TYPE_USHORT_565_RGB:
{
colorModel = new DirectColorModel(16,
DCM_565_RED_MASK,
DCM_565_GRN_MASK,
DCM_565_BLU_MASK
);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
case TYPE_USHORT_555_RGB:
{
colorModel = new DirectColorModel(15,
DCM_555_RED_MASK,
DCM_555_GRN_MASK,
DCM_555_BLU_MASK
);
raster = colorModel.createCompatibleWritableRaster(width,
height);
}
break;
default:
throw new IllegalArgumentException ("Unknown image type " +
imageType);
}
this.imageType = imageType;
| public 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.
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.
if (cm.hasAlpha() && cm.isAlphaPremultiplied()) {
throw new IllegalArgumentException("This image types do not have "+
"premultiplied alpha.");
}
switch(imageType) {
case TYPE_BYTE_BINARY:
int bits; // Will be set below
int mapSize = cm.getMapSize();
if (mapSize <= 2) {
bits = 1;
} else if (mapSize <= 4) {
bits = 2;
} else if (mapSize <= 16) {
bits = 4;
} else {
throw new IllegalArgumentException
("Color map for TYPE_BYTE_BINARY " +
"must have no more than 16 entries");
}
raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
width, height, 1, bits, null);
break;
case TYPE_BYTE_INDEXED:
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height, 1, null);
break;
default:
throw new IllegalArgumentException("Invalid image type (" +
imageType+"). Image type must"+
" be either TYPE_BYTE_BINARY or "+
" TYPE_BYTE_INDEXED");
}
if (!cm.isCompatibleRaster(raster)) {
throw new IllegalArgumentException("Incompatible image type and IndexColorModel");
}
colorModel = cm;
this.imageType = imageType;
| public BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties)Constructs a new 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 {@link 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 {@link Hashtable} of String /Object
pairs.
if (!cm.isCompatibleRaster(raster)) {
throw new
IllegalArgumentException("Raster "+raster+
" is incompatible with ColorModel "+
cm);
}
if ((raster.minX != 0) || (raster.minY != 0)) {
throw new
IllegalArgumentException("Raster "+raster+
" has minX or minY not equal to zero: "
+ raster.minX + " " + raster.minY);
}
colorModel = cm;
this.raster = raster;
this.properties = properties;
int numBands = raster.getNumBands();
boolean isAlphaPre = cm.isAlphaPremultiplied();
ColorSpace cs;
// Force the raster data alpha state to match the premultiplied
// state in the color model
coerceData(isRasterPremultiplied);
SampleModel sm = raster.getSampleModel();
cs = cm.getColorSpace();
int csType = cs.getType();
if (csType != ColorSpace.TYPE_RGB) {
if (csType == ColorSpace.TYPE_GRAY
&& cm instanceof ComponentColorModel) {
// Check if this might be a child raster (fix for bug 4240596)
if (sm instanceof ComponentSampleModel &&
((ComponentSampleModel)sm).getPixelStride() != numBands) {
imageType = TYPE_CUSTOM;
} else if (raster instanceof ByteComponentRaster &&
raster.getNumBands() == 1 &&
cm.getComponentSize(0) == 8 &&
((ByteComponentRaster)raster).getPixelStride() == 1) {
imageType = TYPE_BYTE_GRAY;
} else if (raster instanceof ShortComponentRaster &&
raster.getNumBands() == 1 &&
cm.getComponentSize(0) == 16 &&
((ShortComponentRaster)raster).getPixelStride() == 1) {
imageType = TYPE_USHORT_GRAY;
}
} else {
imageType = TYPE_CUSTOM;
}
return;
}
if ((raster instanceof IntegerComponentRaster) &&
(numBands == 3 || numBands == 4)) {
IntegerComponentRaster iraster =
(IntegerComponentRaster) raster;
// Check if the raster params and the color model
// are correct
int pixSize = cm.getPixelSize();
if (iraster.getPixelStride() == 1 &&
cm instanceof DirectColorModel &&
(pixSize == 32 || pixSize == 24))
{
// Now check on the DirectColorModel params
DirectColorModel dcm = (DirectColorModel) cm;
int rmask = dcm.getRedMask();
int gmask = dcm.getGreenMask();
int bmask = dcm.getBlueMask();
if (rmask == DCM_RED_MASK && gmask == DCM_GREEN_MASK &&
bmask == DCM_BLUE_MASK)
{
if (dcm.getAlphaMask() == DCM_ALPHA_MASK) {
imageType = (isAlphaPre
? TYPE_INT_ARGB_PRE
: TYPE_INT_ARGB);
}
else {
// No Alpha
if (!dcm.hasAlpha()) {
imageType = TYPE_INT_RGB;
}
}
} // if (dcm.getRedMask() == DCM_RED_MASK &&
else if (rmask == DCM_BGR_RED_MASK && gmask == DCM_BGR_GRN_MASK
&& bmask == DCM_BGR_BLU_MASK) {
if (!dcm.hasAlpha()) {
imageType = TYPE_INT_BGR;
}
} // if (rmask == DCM_BGR_RED_MASK &&
} // if (iraster.getPixelStride() == 1
} // ((raster instanceof IntegerComponentRaster) &&
else if ((cm instanceof IndexColorModel) && (numBands == 1) &&
(!cm.hasAlpha() || !isAlphaPre))
{
IndexColorModel icm = (IndexColorModel) cm;
int pixSize = icm.getPixelSize();
if (raster instanceof BytePackedRaster) {
imageType = TYPE_BYTE_BINARY;
} // if (raster instanceof BytePackedRaster)
else if (raster instanceof ByteComponentRaster) {
ByteComponentRaster braster = (ByteComponentRaster) raster;
if (braster.getPixelStride() == 1 && pixSize <= 8) {
imageType = TYPE_BYTE_INDEXED;
}
}
} // else if (cm instanceof IndexColorModel) && (numBands == 1))
else if ((raster instanceof ShortComponentRaster)
&& (cm instanceof DirectColorModel)
&& (numBands == 3)
&& !cm.hasAlpha())
{
DirectColorModel dcm = (DirectColorModel) cm;
if (dcm.getRedMask() == DCM_565_RED_MASK) {
if (dcm.getGreenMask() == DCM_565_GRN_MASK &&
dcm.getBlueMask() == DCM_565_BLU_MASK) {
imageType = TYPE_USHORT_565_RGB;
}
}
else if (dcm.getRedMask() == DCM_555_RED_MASK) {
if (dcm.getGreenMask() == DCM_555_GRN_MASK &&
dcm.getBlueMask() == DCM_555_BLU_MASK) {
imageType = TYPE_USHORT_555_RGB;
}
}
} // else if ((cm instanceof IndexColorModel) && (numBands == 1))
else if ((raster instanceof ByteComponentRaster)
&& (cm instanceof ComponentColorModel)
&& (raster.getSampleModel() instanceof PixelInterleavedSampleModel)
&& (numBands == 3 || numBands == 4))
{
ComponentColorModel ccm = (ComponentColorModel) cm;
PixelInterleavedSampleModel csm =
(PixelInterleavedSampleModel)raster.getSampleModel();
ByteComponentRaster braster = (ByteComponentRaster) raster;
int[] offs = csm.getBandOffsets();
if (ccm.getNumComponents() != numBands) {
throw new RasterFormatException("Number of components in "+
"ColorModel ("+
ccm.getNumComponents()+
") does not match # in "+
" Raster ("+numBands+")");
}
int[] nBits = ccm.getComponentSize();
boolean is8bit = true;
for (int i=0; i < numBands; i++) {
if (nBits[i] != 8) {
is8bit = false;
break;
}
}
if (is8bit &&
offs[0] == numBands-1 &&
offs[1] == numBands-2 &&
offs[2] == numBands-3)
{
if (numBands == 3) {
imageType = TYPE_3BYTE_BGR;
}
else if (offs[3] == 0) {
imageType = (isAlphaPre
? TYPE_4BYTE_ABGR_PRE
: TYPE_4BYTE_ABGR);
}
}
} // else if ((raster instanceof ByteComponentRaster) &&
|
Methods Summary |
---|
public void | addTileObserver(java.awt.image.TileObserver to)Adds a tile observer. If the observer is already present,
it receives multiple notifications.
| 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.
if (colorModel.hasAlpha() &&
colorModel.isAlphaPremultiplied() != isAlphaPremultiplied) {
// Make the color model do the conversion
colorModel = colorModel.coerceData (raster, isAlphaPremultiplied);
}
| public java.awt.image.WritableRaster | copyData(java.awt.image.WritableRaster outRaster)Computes an arbitrary rectangular region of the
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.
if (outRaster == null) {
return (WritableRaster) getData();
}
int width = outRaster.getWidth();
int height = outRaster.getHeight();
int startX = outRaster.getMinX();
int startY = outRaster.getMinY();
Object tdata = null;
for (int i = startY; i < startY+height; i++) {
tdata = raster.getDataElements(startX,i,width,1,tdata);
outRaster.setDataElements(startX,i,width,1, tdata);
}
return outRaster;
| public java.awt.Graphics2D | createGraphics()Creates a Graphics2D , which can be used to draw into
this BufferedImage .
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
return env.createGraphics(this);
| public void | flush()Flushes all resources being used to cache optimization information.
The underlying pixel data is unaffected.
if (surfaceManager != null) {
surfaceManager.flush();
}
| public java.awt.image.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 . 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.
return colorModel.getAlphaRaster(raster);
| public java.awt.ImageCapabilities | getCapabilities(java.awt.GraphicsConfiguration gc)This overrides Image.getCapabilities(gc) to get the capabilities
of its surfaceManager. This means that BufferedImage objects that
are accelerated may return a caps object that will indicate this
acceleration.
if (surfaceManager != null) {
return surfaceManager.getCapabilities(gc);
}
// should not reach here unless the surfaceManager for this image
// has not yet been created
return super.getCapabilities(gc);
| public java.awt.image.ColorModel | getColorModel()Returns the ColorModel .
return colorModel;
| public java.awt.image.Raster | getData()Returns the image as one large tile. The Raster
returned is a copy of the image data is not updated if the
image is changed.
// REMIND : this allocates a whole new tile if raster is a
// subtile. (It only copies in the requested area)
// We should do something smarter.
int width = raster.getWidth();
int height = raster.getHeight();
int startX = raster.getMinX();
int startY = raster.getMinY();
WritableRaster wr =
Raster.createWritableRaster(raster.getSampleModel(),
new Point(raster.getSampleModelTranslateX(),
raster.getSampleModelTranslateY()));
Object tdata = null;
for (int i = startY; i < startY+height; i++) {
tdata = raster.getDataElements(startX,i,width,1,tdata);
wr.setDataElements(startX,i,width,1, tdata);
}
return wr;
| public java.awt.image.Raster | getData(java.awt.Rectangle rect)Computes and returns an arbitrary region of the
BufferedImage . The Raster returned is a
copy of the image data and is not updated if the image is
changed.
SampleModel sm = raster.getSampleModel();
SampleModel nsm = sm.createCompatibleSampleModel(rect.width,
rect.height);
WritableRaster wr = Raster.createWritableRaster(nsm,
rect.getLocation());
int width = rect.width;
int height = rect.height;
int startX = rect.x;
int startY = rect.y;
Object tdata = null;
for (int i = startY; i < startY+height; i++) {
tdata = raster.getDataElements(startX,i,width,1,tdata);
wr.setDataElements(startX,i,width,1, tdata);
}
return wr;
| public java.awt.Graphics | getGraphics()This method returns a {@link Graphics2D}, but is here
for backwards compatibility. {@link #createGraphics() createGraphics} is more
convenient, since it is declared to return a
Graphics2D .
return createGraphics();
| public int | getHeight()Returns the height of the BufferedImage .
return raster.getHeight();
| public int | getHeight(java.awt.image.ImageObserver observer)Returns the height of the BufferedImage .
return raster.getHeight();
| public int | getMinTileX()Returns the minimum tile index in the x direction.
This is always zero.
return 0;
| public int | getMinTileY()Returns the minimum tile index in the y direction.
This is always zero.
return 0;
| public int | getMinX()Returns the minimum x coordinate of this
BufferedImage . This is always zero.
return raster.getMinX();
| public int | getMinY()Returns the minimum y coordinate of this
BufferedImage . This is always zero.
return raster.getMinY();
| public int | getNumXTiles()Returns the number of tiles in the x direction.
This is always one.
return 1;
| public int | getNumYTiles()Returns the number of tiles in the y direction.
This is always one.
return 1;
| public java.lang.Object | getProperty(java.lang.String name, java.awt.image.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 returns the
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.
return getProperty(name);
| public java.lang.Object | getProperty(java.lang.String name)Returns a property of the image by name.
if (name == null) {
throw new NullPointerException("null property name is not allowed");
}
if (properties == null) {
properties = new Hashtable();
}
Object o = properties.get(name);
if (o == null) {
o = java.awt.Image.UndefinedProperty;
}
return o;
| public java.lang.String[] | getPropertyNames()Returns an array of names recognized by
{@link #getProperty(String) getProperty(String)}
or null , if no property names are recognized.
return null;
| 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 image
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.
int yoff = offset;
int off;
Object data;
int nbands = raster.getNumBands();
int dataType = raster.getDataBuffer().getDataType();
switch (dataType) {
case DataBuffer.TYPE_BYTE:
data = new byte[nbands];
break;
case DataBuffer.TYPE_USHORT:
data = new short[nbands];
break;
case DataBuffer.TYPE_INT:
data = new int[nbands];
break;
case DataBuffer.TYPE_FLOAT:
data = new float[nbands];
break;
case DataBuffer.TYPE_DOUBLE:
data = new double[nbands];
break;
default:
throw new IllegalArgumentException("Unknown data buffer type: "+
dataType);
}
if (rgbArray == null) {
rgbArray = new int[offset+h*scansize];
}
for (int y = startY; y < startY+h; y++, yoff+=scansize) {
off = yoff;
for (int x = startX; x < startX+w; x++) {
rgbArray[off++] = colorModel.getRGB(raster.getDataElements(x,
y,
data));
}
}
return rgbArray;
| 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 image 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.
return colorModel.getRGB(raster.getDataElements(x, y, null));
| public java.awt.image.WritableRaster | getRaster()Returns the {@link WritableRaster}.
return raster;
| public java.awt.image.SampleModel | getSampleModel()Returns the SampleModel associated with this
BufferedImage .
return raster.getSampleModel();
| public java.awt.image.ImageProducer | getSource()Returns the object that produces the pixels for the image.
if (osis == null) {
if (properties == null) {
properties = new Hashtable();
}
osis = new OffScreenImageSource(this, properties);
}
return osis;
| public java.util.Vector | getSources()Returns a {@link Vector} of {@link 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.
return null;
| public java.awt.image.BufferedImage | getSubimage(int x, int y, int w, int h)Returns a subimage defined by a specified rectangular region.
The returned BufferedImage shares the same
data array as the original image.
return new BufferedImage (colorModel,
raster.createWritableChild(x, y, w, h,
0, 0, null),
colorModel.isAlphaPremultiplied(),
properties);
| public java.awt.image.Raster | getTile(int tileX, int tileY)Returns tile (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.
if (tileX == 0 && tileY == 0) {
return raster;
}
throw new ArrayIndexOutOfBoundsException("BufferedImages only have"+
" one tile with index 0,0");
| 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.
return raster.getSampleModelTranslateX();
| 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.
return raster.getSampleModelTranslateY();
| public int | getTileHeight()Returns the tile height in pixels.
return raster.getHeight();
| public int | getTileWidth()Returns the tile width in pixels.
return raster.getWidth();
| public int | getTransparency()Returns the transparency. Returns either OPAQUE, BITMASK,
or TRANSLUCENT.
return colorModel.getTransparency();
| public int | getType()Returns the image type. If it is not one of the known types,
TYPE_CUSTOM is returned.
return imageType;
| public int | getWidth()Returns the width of the BufferedImage .
return raster.getWidth();
| public int | getWidth(java.awt.image.ImageObserver observer)Returns the width of the BufferedImage .
return raster.getWidth();
| public java.awt.image.WritableRaster | getWritableTile(int tileX, int tileY)Checks out a tile for writing. All registered
TileObservers are notified when a tile goes from having
no writers to having one writer.
return raster;
| public java.awt.Point[] | getWritableTileIndices()Returns an array of {@link Point} objects indicating which tiles
are checked out for writing. Returns null if none are
checked out.
Point[] p = new Point[1];
p[0] = new Point(0, 0);
return p;
| public boolean | hasTileWriters()Returns whether or not any tile is checked out for writing.
Semantically equivalent to
(getWritableTileIndices() != null).
return true;
| private static native void | initIDs()
| public boolean | isAlphaPremultiplied()Returns whether or not the alpha has been premultiplied. It
returns false if there is no alpha.
return colorModel.isAlphaPremultiplied();
| public boolean | isTileWritable(int tileX, int tileY)Returns whether or not a tile is currently checked out for writing.
if (tileX == 0 && tileY == 0) {
return true;
}
throw new IllegalArgumentException("Only 1 tile in image");
| 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 to {@link #getWritableTile(int, int) 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.
| public void | removeTileObserver(java.awt.image.TileObserver to)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.
| public void | setData(java.awt.image.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 . The operation is clipped to the bounds
of the BufferedImage .
int width = r.getWidth();
int height = r.getHeight();
int startX = r.getMinX();
int startY = r.getMinY();
int[] tdata = null;
// Clip to the current Raster
Rectangle rclip = new Rectangle(startX, startY, width, height);
Rectangle bclip = new Rectangle(0, 0, raster.width, raster.height);
Rectangle intersect = rclip.intersection(bclip);
if (intersect.isEmpty()) {
return;
}
width = intersect.width;
height = intersect.height;
startX = intersect.x;
startY = intersect.y;
// remind use get/setDataElements for speed if Rasters are
// compatible
for (int i = startY; i < startY+height; i++) {
tdata = r.getPixels(startX,i,width,1,tdata);
raster.setPixels(startX,i,width,1, tdata);
}
| public synchronized void | setRGB(int x, int y, int rgb)Sets a pixel in this 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.
raster.setDataElements(x, y, colorModel.getDataElements(rgb, null));
| 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 image
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.
int yoff = offset;
int off;
Object pixel = null;
for (int y = startY; y < startY+h; y++, yoff+=scansize) {
off = yoff;
for (int x = startX; x < startX+w; x++) {
pixel = colorModel.getDataElements(rgbArray[off++], pixel);
raster.setDataElements(x, y, pixel);
}
}
| public java.lang.String | toString()Returns a String representation of this
BufferedImage object and its values.
return new String("BufferedImage@"+Integer.toHexString(hashCode())
+": type = "+imageType
+" "+colorModel+" "+raster);
|
|