java.awt.image
Class BufferedImage

java.lang.Object
  extended by java.awt.Image
      extended by java.awt.image.BufferedImage
All Implemented Interfaces:
RenderedImage, WritableRenderedImage, Transparency

public class BufferedImage
extends Image
implements WritableRenderedImage, Transparency

A buffered image always starts at coordinates (0, 0). The buffered image is not subdivided into multiple tiles. Instead, the image consists of one large tile (0,0) with the width and height of the image. This tile is always considered to be checked out.


Field Summary
static int TYPE_3BYTE_BGR
           
static int TYPE_4BYTE_ABGR
           
static int TYPE_4BYTE_ABGR_PRE
           
static int TYPE_BYTE_BINARY
           
static int TYPE_BYTE_GRAY
           
static int TYPE_BYTE_INDEXED
           
static int TYPE_CUSTOM
           
static int TYPE_INT_ARGB
           
static int TYPE_INT_ARGB_PRE
           
static int TYPE_INT_BGR
           
static int TYPE_INT_RGB
           
static int TYPE_USHORT_555_RGB
           
static int TYPE_USHORT_565_RGB
           
static int TYPE_USHORT_GRAY
           
 
Fields inherited from class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
BufferedImage(ColorModel colormodel, WritableRaster writableraster, boolean premultiplied, Hashtable<?,?> properties)
           
BufferedImage(int width, int height, int type)
          Creates a new BufferedImage with the specified width, height and type.
BufferedImage(int w, int h, int type, IndexColorModel indexcolormodel)
           
 
Method Summary
 void addTileObserver(TileObserver to)
          Adds a tile observer.
 void coerceData(boolean premultiplied)
           
 WritableRaster copyData(WritableRaster dest)
           
 Graphics2D createGraphics()
           
 void flush()
          Flushes (that is, destroys) any resources used for this image.
 WritableRaster getAlphaRaster()
           
 ColorModel getColorModel()
           
 Raster getData()
           
 Raster getData(Rectangle rectangle)
           
 Graphics getGraphics()
          Returns a graphics context object for drawing an off-screen object.
 int getHeight()
           
 int getHeight(ImageObserver imageobserver)
          Returns the height of the image, or -1 if it is unknown.
 int getMinTileX()
           
 int getMinTileY()
           
 int getMinX()
           
 int getMinY()
           
 int getNumXTiles()
           
 int getNumYTiles()
           
 Object getProperty(String string)
          Returns the value of the specified property, or Image.UndefinedProperty if the property is not defined.
 Object getProperty(String string, ImageObserver imageobserver)
          This method requests a named property for an object.
 String[] getPropertyNames()
          Returns null always.
 WritableRaster getRaster()
           
 int getRGB(int x, int y)
           
 int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scanlineStride)
           
 SampleModel getSampleModel()
           
 ImageProducer getSource()
          Returns the image producer object for this object.
 Vector<RenderedImage> getSources()
           
 BufferedImage getSubimage(int x, int y, int w, int h)
           
 Raster getTile(int tileX, int tileY)
           
 int getTileGridXOffset()
           
 int getTileGridYOffset()
           
 int getTileHeight()
           
 int getTileWidth()
           
 int getTransparency()
          Return the transparency type.
 int getType()
           
 int getWidth()
           
 int getWidth(ImageObserver imageobserver)
          Returns the width of the image, or -1 if it is unknown.
 WritableRaster getWritableTile(int tileX, int tileY)
           
 Point[] getWritableTileIndices()
           
 boolean hasTileWriters()
           
 boolean isAlphaPremultiplied()
           
 boolean isTileWritable(int tileX, int tileY)
           
 void releaseWritableTile(int tileX, int tileY)
           
 void removeTileObserver(TileObserver to)
          Removes a tile observer.
 void setData(Raster src)
           
 void setRGB(int x, int y, int argb)
           
 void setRGB(int startX, int startY, int w, int h, int[] argbArray, int offset, int scanlineStride)
           
 String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.awt.Image
getAccelerationPriority, getScaledInstance, setAccelerationPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_CUSTOM

public static final int TYPE_CUSTOM
See Also:
Constant Field Values

TYPE_INT_RGB

public static final int TYPE_INT_RGB
See Also:
Constant Field Values

TYPE_INT_ARGB

public static final int TYPE_INT_ARGB
See Also:
Constant Field Values

TYPE_INT_ARGB_PRE

public static final int TYPE_INT_ARGB_PRE
See Also:
Constant Field Values

TYPE_INT_BGR

public static final int TYPE_INT_BGR
See Also:
Constant Field Values

TYPE_3BYTE_BGR

public static final int TYPE_3BYTE_BGR
See Also:
Constant Field Values

TYPE_4BYTE_ABGR

public static final int TYPE_4BYTE_ABGR
See Also:
Constant Field Values

TYPE_4BYTE_ABGR_PRE

public static final int TYPE_4BYTE_ABGR_PRE
See Also:
Constant Field Values

TYPE_USHORT_565_RGB

public static final int TYPE_USHORT_565_RGB
See Also:
Constant Field Values

TYPE_USHORT_555_RGB

public static final int TYPE_USHORT_555_RGB
See Also:
Constant Field Values

TYPE_BYTE_GRAY

public static final int TYPE_BYTE_GRAY
See Also:
Constant Field Values

TYPE_USHORT_GRAY

public static final int TYPE_USHORT_GRAY
See Also:
Constant Field Values

TYPE_BYTE_BINARY

public static final int TYPE_BYTE_BINARY
See Also:
Constant Field Values

TYPE_BYTE_INDEXED

public static final int TYPE_BYTE_INDEXED
See Also:
Constant Field Values
Constructor Detail

BufferedImage

public BufferedImage(int width,
                     int height,
                     int type)
Creates a new BufferedImage with the specified width, height and type. Valid type values are:

Parameters:
width - the width (must be > 0).
height - the height (must be > 0).
type - the image type (see the list of valid types above).
Throws:
IllegalArgumentException - if width or height is less than or equal to zero.
IllegalArgumentException - if type is not one of the specified values.

BufferedImage

public BufferedImage(int w,
                     int h,
                     int type,
                     IndexColorModel indexcolormodel)

BufferedImage

public BufferedImage(ColorModel colormodel,
                     WritableRaster writableraster,
                     boolean premultiplied,
                     Hashtable<?,?> properties)
Method Detail

coerceData

public void coerceData(boolean premultiplied)

copyData

public WritableRaster copyData(WritableRaster dest)
Specified by:
copyData in interface RenderedImage

createGraphics

public Graphics2D createGraphics()

flush

public void flush()
Description copied from class: Image
Flushes (that is, destroys) any resources used for this image. This includes the actual image data.

Specified by:
flush in class Image

getAlphaRaster

public WritableRaster getAlphaRaster()

getColorModel

public ColorModel getColorModel()
Specified by:
getColorModel in interface RenderedImage

getData

public Raster getData()
Specified by:
getData in interface RenderedImage

getData

public Raster getData(Rectangle rectangle)
Specified by:
getData in interface RenderedImage

getGraphics

public Graphics getGraphics()
Description copied from class: Image
Returns a graphics context object for drawing an off-screen object. This method is only valid for off-screen objects.

Specified by:
getGraphics in class Image
Returns:
a graphics context object for an off-screen object

getHeight

public int getHeight()
Specified by:
getHeight in interface RenderedImage

getHeight

public int getHeight(ImageObserver imageobserver)
Description copied from class: Image
Returns the height of the image, or -1 if it is unknown. If the image height is unknown, the observer object will be notified when the value is known.

Specified by:
getHeight in class Image
Parameters:
imageobserver - the image observer for this object
Returns:
the height in pixels
See Also:
Image.getWidth(ImageObserver)

getMinTileX

public int getMinTileX()
Specified by:
getMinTileX in interface RenderedImage

getMinTileY

public int getMinTileY()
Specified by:
getMinTileY in interface RenderedImage

getMinX

public int getMinX()
Specified by:
getMinX in interface RenderedImage

getMinY

public int getMinY()
Specified by:
getMinY in interface RenderedImage

getNumXTiles

public int getNumXTiles()
Specified by:
getNumXTiles in interface RenderedImage

getNumYTiles

public int getNumYTiles()
Specified by:
getNumYTiles in interface RenderedImage

getProperty

public Object getProperty(String string)
Returns the value of the specified property, or Image.UndefinedProperty if the property is not defined.

Specified by:
getProperty in interface RenderedImage
Parameters:
string - the property key (null not permitted).
Returns:
The property value.
Throws:
NullPointerException - if string is null.

getProperty

public Object getProperty(String string,
                          ImageObserver imageobserver)
Description copied from class: Image
This method requests a named property for an object. The value of the property is returned. The value UndefinedProperty is returned if there is no property with the specified name. The value null is returned if the properties for the object are not yet known. In this case, the specified image observer is notified when the properties are known.

Specified by:
getProperty in class Image
Parameters:
string - the requested property name
imageobserver - the image observer for this object
Returns:
the named property, if available
See Also:
Image.UndefinedProperty

getPropertyNames

public String[] getPropertyNames()
Returns null always.

Specified by:
getPropertyNames in interface RenderedImage
Returns:
null always.

getRGB

public int getRGB(int x,
                  int y)

getRGB

public int[] getRGB(int startX,
                    int startY,
                    int w,
                    int h,
                    int[] rgbArray,
                    int offset,
                    int scanlineStride)

getRaster

public WritableRaster getRaster()

getSampleModel

public SampleModel getSampleModel()
Specified by:
getSampleModel in interface RenderedImage

getSource

public ImageProducer getSource()
Description copied from class: Image
Returns the image producer object for this object. The producer is the object which generates pixels for this image.

Specified by:
getSource in class Image
Returns:
the image producer for this object

getSources

public Vector<RenderedImage> getSources()
Specified by:
getSources in interface RenderedImage

getSubimage

public BufferedImage getSubimage(int x,
                                 int y,
                                 int w,
                                 int h)

getTile

public Raster getTile(int tileX,
                      int tileY)
Specified by:
getTile in interface RenderedImage

getTileGridXOffset

public int getTileGridXOffset()
Specified by:
getTileGridXOffset in interface RenderedImage

getTileGridYOffset

public int getTileGridYOffset()
Specified by:
getTileGridYOffset in interface RenderedImage

getTileHeight

public int getTileHeight()
Specified by:
getTileHeight in interface RenderedImage

getTileWidth

public int getTileWidth()
Specified by:
getTileWidth in interface RenderedImage

getType

public int getType()

getWidth

public int getWidth()
Specified by:
getWidth in interface RenderedImage

getWidth

public int getWidth(ImageObserver imageobserver)
Description copied from class: Image
Returns the width of the image, or -1 if it is unknown. If the image width is unknown, the observer object will be notified when the value is known.

Specified by:
getWidth in class Image
Parameters:
imageobserver - the image observer for this object
Returns:
the width in pixels
See Also:
Image.getHeight(ImageObserver)

getWritableTile

public WritableRaster getWritableTile(int tileX,
                                      int tileY)
Specified by:
getWritableTile in interface WritableRenderedImage

getWritableTileIndices

public Point[] getWritableTileIndices()
Specified by:
getWritableTileIndices in interface WritableRenderedImage

hasTileWriters

public boolean hasTileWriters()
Specified by:
hasTileWriters in interface WritableRenderedImage

isAlphaPremultiplied

public boolean isAlphaPremultiplied()

isTileWritable

public boolean isTileWritable(int tileX,
                              int tileY)
Specified by:
isTileWritable in interface WritableRenderedImage

releaseWritableTile

public void releaseWritableTile(int tileX,
                                int tileY)
Specified by:
releaseWritableTile in interface WritableRenderedImage

setData

public void setData(Raster src)
Specified by:
setData in interface WritableRenderedImage

setRGB

public void setRGB(int x,
                   int y,
                   int argb)

setRGB

public void setRGB(int startX,
                   int startY,
                   int w,
                   int h,
                   int[] argbArray,
                   int offset,
                   int scanlineStride)

toString

public String toString()
Description copied from class: Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() and such.

It is typical, but not required, to ensure that this method never completes abruptly with a RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

Overrides:
toString in class Object
Returns:
the String representing this Object, which may be null
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

addTileObserver

public void addTileObserver(TileObserver to)
Adds a tile observer. If the observer is already present, it receives multiple notifications.

Specified by:
addTileObserver in interface WritableRenderedImage
Parameters:
to - The TileObserver to add.

removeTileObserver

public void removeTileObserver(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.

Specified by:
removeTileObserver in interface WritableRenderedImage
Parameters:
to - The TileObserver to remove.

getTransparency

public int getTransparency()
Return the transparency type.

Specified by:
getTransparency in interface Transparency
Returns:
One of Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT.
Since:
1.5
See Also:
Transparency.getTransparency()