JavaTM Platform
Standard Ed. 6

java.awt.image
类 BufferedImage

java.lang.Object
  继承者 java.awt.Image
      继承者 java.awt.image.BufferedImage
所有已实现的接口:
RenderedImage, WritableRenderedImage, Transparency

public class BufferedImage
extends Image
implements WritableRenderedImage, Transparency

BufferedImage 子类描述具有可访问图像数据缓冲区的 ImageBufferedImage 由图像数据的 ColorModelRaster 组成。RasterSampleModel 中 band 的数量和类型必须与 ColorModel 所要求的数量和类型相匹配,以表示其颜色和 alpha 分量。所有 BufferedImage 对象的左上角坐标都为 (0, 0)。因此,用来构造 BufferedImage 的任何 Raster 都必须满足:minX=0 且 minY=0。

此类依靠 Raster 的数据获取方法、数据设置方法,以及 ColorModel 的颜色特征化方法。

另请参见:
ColorModel, Raster, WritableRaster

字段摘要
static int TYPE_3BYTE_BGR
          表示一个具有 8 位 RGB 颜色分量的图像,对应于 Windows 风格的 BGR 颜色模型,具有用 3 字节存储的 Blue、Green 和 Red 三种颜色。
static int TYPE_4BYTE_ABGR
          表示一个具有 8 位 RGBA 颜色分量的图像,具有用 3 字节存储的 Blue、Green 和 Red 颜色以及 1 字节的 alpha。
static int TYPE_4BYTE_ABGR_PRE
          表示一个具有 8 位 RGBA 颜色分量的图像,具有用 3 字节存储的 Blue、Green 和 Red 颜色以及 1 字节的 alpha。
static int TYPE_BYTE_BINARY
          表示一个不透明的以字节打包的 1、2 或 4 位图像。
static int TYPE_BYTE_GRAY
          表示无符号 byte 灰度级图像(无索引)。
static int TYPE_BYTE_INDEXED
          表示带索引的字节图像。
static int TYPE_CUSTOM
          没有识别出图像类型,因此它必定是一个自定义图像。
static int TYPE_INT_ARGB
          表示一个图像,它具有合成整数像素的 8 位 RGBA 颜色分量。
static int TYPE_INT_ARGB_PRE
          表示一个图像,它具有合成整数像素的 8 位 RGBA 颜色分量。
static int TYPE_INT_BGR
          表示一个具有 8 位 RGB 颜色分量的图像,对应于 Windows 或 Solaris 风格的 BGR 颜色模型,具有打包为整数像素的 Blue、Green 和 Red 三种颜色。
static int TYPE_INT_RGB
          表示一个图像,它具有合成整数像素的 8 位 RGB 颜色分量。
static int TYPE_USHORT_555_RGB
          表示一个具有 5-5-5 RGB 颜色分量(5 位 red、5 位 green、5 位 blue)的图像,不带 alpha。
static int TYPE_USHORT_565_RGB
          表示一个具有 5-6-5 RGB 颜色分量(5 位 red、6 位 green、5 位 blue)的图像,不带 alpha。
static int TYPE_USHORT_GRAY
          表示一个无符号 short 灰度级图像(无索引)。
 
从类 java.awt.Image 继承的字段
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
从接口 java.awt.Transparency 继承的字段
BITMASK, OPAQUE, TRANSLUCENT
 
构造方法摘要
BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)
          构造一个具有指定 ColorModelRaster 的新 BufferedImage
BufferedImage(int width, int height, int imageType)
          构造一个类型为预定义图像类型之一的 BufferedImage
BufferedImage(int width, int height, int imageType, IndexColorModel cm)
          构造一个类型为预定义图像类型之一的 BufferedImage:TYPE_BYTE_BINARY 或 TYPE_BYTE_INDEXED。
 
方法摘要
 void addTileObserver(TileObserver to)
          添加一个 tile observer。
 void coerceData(boolean isAlphaPremultiplied)
          强制该数据与 isAlphaPremultiplied 变量中指定的状态相匹配。
 WritableRaster copyData(WritableRaster outRaster)
          计算 BufferedImage 的一个任意矩形区域,并将其复制到指定的 WritableRaster
 Graphics2D createGraphics()
          创建一个 Graphics2D,可以将它绘制到此 BufferedImage 中。
 WritableRaster getAlphaRaster()
          返回一个 WritableRaster,它使用支持单独空间 alpha 通道的 ColorModel 对象(比如 ComponentColorModelDirectColorModel)表示 BufferedImage 对象的 alpha 通道。
 ColorModel getColorModel()
          返回 ColorModel
 Raster getData()
          以一个大 tile 的形式返回图像。
 Raster getData(Rectangle rect)
          计算并返回 BufferedImage 的一个任意区域。
 Graphics getGraphics()
          此方法返回 Graphics2D,但此处是出于向后兼容性的考虑。
 int getHeight()
          返回 BufferedImage 的高度。
 int getHeight(ImageObserver observer)
          返回 BufferedImage 的高度。
 int getMinTileX()
          返回 x 方向的最小 tile 索引。
 int getMinTileY()
          返回 y 方向的最小 tile 索引。
 int getMinX()
          返回此 BufferedImage 的最小 x 坐标。
 int getMinY()
          返回此 BufferedImage 的最小 y 坐标。
 int getNumXTiles()
          返回 x 方向的 tile 数。
 int getNumYTiles()
          返回 y 方向的 tile 数。
 Object getProperty(String name)
          按名称返回图像的属性。
 Object getProperty(String name, ImageObserver observer)
          按名称返回图像的属性。
 String[] getPropertyNames()
          返回由 getProperty(String) 识别的名称数组;如果没有识别出属性名,则返回 null
 WritableRaster getRaster()
          返回 WritableRaster
 int getRGB(int x, int y)
          返回默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中的整数像素。
 int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
          从图像数据的某一部分返回默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中整数像素数组。
 SampleModel getSampleModel()
          返回与此 BufferedImage 关联的 SampleModel
 ImageProducer getSource()
          返回生成该图像像素的对象。
 Vector<RenderedImage> getSources()
          返回 RenderedImage 对象的 Vector,该对象是此 BufferedImage 图像数据的直接来源,而不是这些直接来源的来源。
 BufferedImage getSubimage(int x, int y, int w, int h)
          返回由指定矩形区域定义的子图像。
 Raster getTile(int tileX, int tileY)
          返回 tile (tileXtileY)。
 int getTileGridXOffset()
          返回 tile 网格相对于原点的 x 偏移量(例如,tile (0, 0) 位置的 x 坐标)。
 int getTileGridYOffset()
          返回 tile 网格相对于原点的 y 偏移量(例如,tile (0, 0) 位置的 y 坐标)。
 int getTileHeight()
          返回 tile 高度(以像素为单位)。
 int getTileWidth()
          返回 tile 宽度(以像素为单位)。
 int getTransparency()
          返回透明度。
 int getType()
          返回图像类型。
 int getWidth()
          返回 BufferedImage 的宽度。
 int getWidth(ImageObserver observer)
          返回 BufferedImage 的宽度。
 WritableRaster getWritableTile(int tileX, int tileY)
          为写入签出一个 tile。
 Point[] getWritableTileIndices()
          返回 Point 对象的数组,它指示为写入签出了哪些 tile。
 boolean hasTileWriters()
          返回是否有为写入签出的 tile。
 boolean isAlphaPremultiplied()
          返回是否已预乘以 alpha。
 boolean isTileWritable(int tileX, int tileY)
          返回当前是否为写入签出 tile。
 void releaseWritableTile(int tileX, int tileY)
          放弃写入一个 tile 的权限。
 void removeTileObserver(TileObserver to)
          移除一个 tile observer。
 void setData(Raster r)
          将图像的矩形区域设置为指定 Raster r 的内容,假定该区域与 BufferedImage 处于相同的坐标空间。
 void setRGB(int x, int y, int rgb)
          将此 BufferedImage 中的像素设置为指定的 RGB 值。
 void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
          将默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中的整数像素数组设置为图像数据的一部分。
 String toString()
          返回此 BufferedImage 对象及其值的 String 表示形式。
 
从类 java.awt.Image 继承的方法
flush, getAccelerationPriority, getCapabilities, getScaledInstance, setAccelerationPriority
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

TYPE_CUSTOM

public static final int TYPE_CUSTOM
没有识别出图像类型,因此它必定是一个自定义图像。此类型仅用作 getType() 方法的返回值。

另请参见:
常量字段值

TYPE_INT_RGB

public static final int TYPE_INT_RGB
表示一个图像,它具有合成整数像素的 8 位 RGB 颜色分量。该图像具有不带 alpha 的 DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_INT_ARGB

public static final int TYPE_INT_ARGB
表示一个图像,它具有合成整数像素的 8 位 RGBA 颜色分量。该图像具有带 alpha 的 DirectColorModel。认为此图像中的颜色数据没有预乘以 alpha。当使用此类型作为 BufferedImage 构造方法的 imageType 参数时,所创建的图像与 JDK1.1 和更早期版本中创建的图像一致。

另请参见:
常量字段值

TYPE_INT_ARGB_PRE

public static final int TYPE_INT_ARGB_PRE
表示一个图像,它具有合成整数像素的 8 位 RGBA 颜色分量。该图像具有带 alpha 的 DirectColorModel。认为此图像中的颜色数据已预乘以 alpha。

另请参见:
常量字段值

TYPE_INT_BGR

public static final int TYPE_INT_BGR
表示一个具有 8 位 RGB 颜色分量的图像,对应于 Windows 或 Solaris 风格的 BGR 颜色模型,具有打包为整数像素的 Blue、Green 和 Red 三种颜色。不存在 alpha。该图像具有一个 DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_3BYTE_BGR

public static final int TYPE_3BYTE_BGR
表示一个具有 8 位 RGB 颜色分量的图像,对应于 Windows 风格的 BGR 颜色模型,具有用 3 字节存储的 Blue、Green 和 Red 三种颜色。不存在 alpha。该图像具有一个 ComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_4BYTE_ABGR

public static final int TYPE_4BYTE_ABGR
表示一个具有 8 位 RGBA 颜色分量的图像,具有用 3 字节存储的 Blue、Green 和 Red 颜色以及 1 字节的 alpha。该图像具有带 alpha 的 ComponentColorModel。认为此图像中的颜色数据没有预乘以 alpha。按照每个像素中字节地址从低到高的顺序 A、B、G、R 将字节数据插入单个字节数组中。

另请参见:
常量字段值

TYPE_4BYTE_ABGR_PRE

public static final int TYPE_4BYTE_ABGR_PRE
表示一个具有 8 位 RGBA 颜色分量的图像,具有用 3 字节存储的 Blue、Green 和 Red 颜色以及 1 字节的 alpha。该图像具有带 alpha 的 ComponentColorModel。认为此图像中的颜色数据已预乘以 alpha。按照每个像素中字节地址从低到高的顺序 A、B、G、R 将字节数据插入单个字节数组中。

另请参见:
常量字段值

TYPE_USHORT_565_RGB

public static final int TYPE_USHORT_565_RGB
表示一个具有 5-6-5 RGB 颜色分量(5 位 red、6 位 green、5 位 blue)的图像,不带 alpha。该图像具有一个 DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_USHORT_555_RGB

public static final int TYPE_USHORT_555_RGB
表示一个具有 5-5-5 RGB 颜色分量(5 位 red、5 位 green、5 位 blue)的图像,不带 alpha。此图像具有一个 DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_BYTE_GRAY

public static final int TYPE_BYTE_GRAY
表示无符号 byte 灰度级图像(无索引)。该图像具有带 CS_GRAY ColorSpaceComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_USHORT_GRAY

public static final int TYPE_USHORT_GRAY
表示一个无符号 short 灰度级图像(无索引)。该图像具有带 CS_GRAY ColorSpaceComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 AlphaComposite 文档中的描述。

另请参见:
常量字段值

TYPE_BYTE_BINARY

public static final int TYPE_BYTE_BINARY
表示一个不透明的以字节打包的 1、2 或 4 位图像。该图像具有不带 alpha 的 IndexColorModel。当此类型用作 BufferedImage 构造方法(带 imageType 参数而不是 ColorModel 参数)的 imageType 参数时,创建一个 1 位图像,且其 IndexColorModel 具有默认 sRGB ColorSpace 中的两种颜色:{0, 0, 0} 和 {255, 255, 255}。

每个像素 2 位或 4 位的图像可以通过 BufferedImage 构造方法构造,该构造方法带一个 ColorModel 参数,这通过提供一个具有合适映射大小的 ColorModel 实现。

每个像素 8 位的图像应该使用 TYPE_BYTE_INDEXEDTYPE_BYTE_GRAY 图像类型,具体取决于它们的 ColorModel

当颜色数据存储在此类型的图像中时,由 IndexColorModel 确定 colormap 中最接近的颜色,并存储得到的索引。根据 IndexColorModel colormap 中的颜色,可以得到 alpha 分量或颜色分量的近似值及丢失的 alpha 或颜色分量。

另请参见:
常量字段值

TYPE_BYTE_INDEXED

public static final int TYPE_BYTE_INDEXED
表示带索引的字节图像。当此类型用作 BufferedImage 构造方法(带 imageType 参数而不带 ColorModel 参数 )的 imageType 参数时,创建一个 IndexColorModel,它具有 256 色 6/6/6 三色调色板,其余从 216 到 255 的颜色由默认 sRGB ColorSpace 的灰度级值填充。

当颜色数据存储在此类型的图像中时,由 IndexColorModel 确定 colormap 中最接近的颜色,并存储得到的索引。根据 IndexColorModel colormap 中的颜色,可以得到 alpha 分量或颜色分量的近似值及丢失的 alpha 或颜色分量。

另请参见:
常量字段值
构造方法详细信息

BufferedImage

public BufferedImage(int width,
                     int height,
                     int imageType)
构造一个类型为预定义图像类型之一的 BufferedImage。该图像的 ColorSpace 为默认的 sRGB 空间。

参数:
width - 所创建图像的宽度
height - 所创建图像的高度
imageType - 所创建图像的类型
另请参见:
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

public BufferedImage(int width,
                     int height,
                     int imageType,
                     IndexColorModel cm)
构造一个类型为预定义图像类型之一的 BufferedImage:TYPE_BYTE_BINARY 或 TYPE_BYTE_INDEXED。

如果图像类型为 TYPE_BYTE_BINARY,则使用颜色模型中的条目数确定图像的每像素具有 1、2 还是 4 位。如果颜色模型具有 1 或 2 个条目,则该图像每像素具有 1 位。如果颜色模型具有 3 或 4 个条目,则该图像的每像素具有 2 位。如果颜色模型的条目数在 5 到 16 之间,则该图像的每像素具有 4 位。否则,将抛出 IllegalArgumentException。

参数:
width - 所创建图像的宽度
height - 所创建图像的高度
imageType - 所创建图像的类型
cm - 所创建图像的 IndexColorModel
抛出:
IllegalArgumentException - 如果 imageType 不为 TYPE_BYTE_BINARY 或 TYPE_BYTE_INDEXED,或者 imageType 为 TYPE_BYTE_BINARY 且颜色映射的条目数大于 16。
另请参见:
TYPE_BYTE_BINARY, TYPE_BYTE_INDEXED

BufferedImage

public BufferedImage(ColorModel cm,
                     WritableRaster raster,
                     boolean isRasterPremultiplied,
                     Hashtable<?,?> properties)
构造一个具有指定 ColorModelRaster 的新 BufferedImage。如果 RasterSampleModel 中 band 的数量和类型与 ColorModel(表示其颜色和 alpha 分量)所要求的数量和类型不匹配,则抛出 RasterFormatException。此方法可以将 Raster 颜色数据乘以或除以 alpha,以匹配 ColorModel 中的 alphaPremultiplied 状态。可以通过传入 String/Object 对的 Hashtable 建立此 BufferedImage 的属性。

参数:
cm - 新图像的 ColorModel
raster - 图像数据的 Raster
isRasterPremultiplied - 如果为 true,则 raster 中的数据已预乘以 alpha。
properties - String/Object 对的 Hashtable
抛出:
RasterFormatException - 如果 RasterSampleModel 中 band 的数量和类型与 ColorModel(表示其颜色和 alpha 分量)所要求的数量和类型不匹配。
IllegalArgumentException - 如果 rastercm 不一致
另请参见:
ColorModel, Raster, WritableRaster
方法详细信息

getType

public int getType()
返回图像类型。如果它不是已知的类型之一,则返回 TYPE_CUSTOM 。

返回:
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

getColorModel

public ColorModel getColorModel()
返回 ColorModel

指定者:
接口 RenderedImage 中的 getColorModel
返回:
BufferedImageColorModel

getRaster

public WritableRaster getRaster()
返回 WritableRaster

返回:
BufferedImageWriteableRaster

getAlphaRaster

public WritableRaster getAlphaRaster()
返回一个 WritableRaster,它使用支持单独空间 alpha 通道的 ColorModel 对象(比如 ComponentColorModelDirectColorModel)表示 BufferedImage 对象的 alpha 通道。如果此图像中没有与 ColorModel 关联的 alpha 通道,则返回 null。此方法假定 IndexColorModel 之外的所有 ColorModel 对象都具有一个单独的 alpha 通道(如果 ColorModel 支持 alpha),该通道存储为图像数据的最后一个 band。如果该图像使用查找表中一个具有 alpha 的 IndexColorModel,则此方法返回 null,因为不存在空间上离散的 alpha 通道。此方法创建一个新的 WritableRaster,但是共享原数据数组。

返回:
WritableRaster;如果此 BufferedImage 不具有与其 ColorModel 关联的 alpha 通道,则返回 null

getRGB

public int getRGB(int x,
                  int y)
返回默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中的整数像素。如果此默认模型与该图像的 ColorModel 不匹配,则发生颜色转换。在使用此方法所返回的数据中,每个颜色分量只有 8 位精度。

如果坐标不在边界内部,则抛出 ArrayOutOfBoundsException。但是,不保证进行显式的边界检查。

参数:
x - 像素的 X 坐标,从该坐标可以得到默认 RGB 颜色模型和 sRGB 颜色空间中的像素
y - 像素的 Y 坐标,从该坐标可以得到默认 RGB 颜色模型和 sRGB 颜色空间中的像素
返回:
默认 RGB 颜色模型和默认 sRGB 颜色空间中的整数像素。
另请参见:
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)
从图像数据的某一部分返回默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中整数像素数组。如果该默认模型与该图像的 ColorModel 不匹配,则发生颜色转换。在使用此方法所返回的数据中,每个颜色分量只有 8 位精度。通过图像中指定的坐标 (x, y),ARGB 像素可以按如下方式访问:

    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)]; 

如果该区域不在边界内部,则抛出 ArrayOutOfBoundsException。但是,不保证进行显式的边界检查。

参数:
startX - 起始 X 坐标
startY - 起始 Y 坐标
w - 区域的宽度
h - 区域的高度
rgbArray - 如果不为 null,则在此写入 rgb 像素
offset - rgbArray 中的偏移量
scansize - rgbArray 的扫描行间距
返回:
RGB 像素数组。
另请参见:
setRGB(int, int, int), setRGB(int, int, int, int, int[], int, int)

setRGB

public void setRGB(int x,
                   int y,
                   int rgb)
将此 BufferedImage 中的像素设置为指定的 RGB 值。假定该像素使用默认 RGB 颜色模型、TYPE_INT_ARGB 和默认 sRGB 颜色空间。对于具有 IndexColorModel 的图像,则选择最接近的颜色的索引。

如果坐标不在边界内部,则抛出 ArrayOutOfBoundsException。但是,不保证进行显式的边界检查。

参数:
x - 要设置的像素的 X 坐标
y - 要设置的像素的 Y 坐标
rgb - RGB 值
另请参见:
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)
将默认 RGB 颜色模型 (TYPE_INT_ARGB) 和默认 sRGB 颜色空间中的整数像素数组设置为图像数据的一部分。如果该默认模型与该图像的 ColorModel 不匹配,则发生颜色转换。在使用此方法所返回的数据中,每个颜色分量只有 8 位精度。通过此图像中指定的坐标 (x, y),ARGB 像素可以按如下方式访问:
    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
 
警告:无抖动发生。

如果该区域不在边界内部,则抛出 ArrayOutOfBoundsException。但是,不保证进行显式的边界检查。

参数:
startX - 起始 X 坐标
startY - 起始 Y 坐标
w - 区域的宽度
h - 区域的高度
rgbArray - rgb 像素
offset - rgbArray 中的偏移量
scansize - rgbArray 的扫描行间距
另请参见:
getRGB(int, int), getRGB(int, int, int, int, int[], int, int)

getWidth

public int getWidth()
返回 BufferedImage 的宽度。

指定者:
接口 RenderedImage 中的 getWidth
返回:
BufferedImage 的宽度

getHeight

public int getHeight()
返回 BufferedImage 的高度。

指定者:
接口 RenderedImage 中的 getHeight
返回:
BufferedImage 的高度

getWidth

public int getWidth(ImageObserver observer)
返回 BufferedImage 的宽度。

指定者:
Image 中的 getWidth
参数:
observer - 忽略
返回:
BufferedImage 的宽度
另请参见:
Image.getHeight(java.awt.image.ImageObserver), ImageObserver

getHeight

public int getHeight(ImageObserver observer)
返回 BufferedImage 的高度。

指定者:
Image 中的 getHeight
参数:
observer - 忽略
返回:
BufferedImage 的高度
另请参见:
Image.getWidth(java.awt.image.ImageObserver), ImageObserver

getSource

public ImageProducer getSource()
返回生成该图像像素的对象。

指定者:
Image 中的 getSource
返回:
用于生成该图像像素的 ImageProducer
另请参见:
ImageProducer

getProperty

public Object getProperty(String name,
                          ImageObserver observer)
按名称返回图像的属性。个别属性名可用各种图像格式定义。如果属性不是为特定图像定义的,则此方法返回 UndefinedProperty 字段。如果此图像的属性目前未知,则此方法返回 null,然后通知 ImageObserver 对象。属性名 "comment" 应该用于存储可选注释,它可以作为对图像的描述(来源或作者)呈现给用户。

指定者:
Image 中的 getProperty
参数:
name - 属性名
observer - 接收关于图像信息通知的 ImageObserver
返回:
Object,它是由指定 name 所引用的属性;如果此图像的属性未知,则返回 null
抛出:
NullPointerException - 如果属性名为 null。
另请参见:
ImageObserver, Image.UndefinedProperty

getProperty

public Object getProperty(String name)
按名称返回图像的属性。

指定者:
接口 RenderedImage 中的 getProperty
参数:
name - 属性名
返回:
Object,它是由指定 name 所引用的属性。
抛出:
NullPointerException - 如果属性名为 null。
另请参见:
Image.UndefinedProperty

getGraphics

public Graphics getGraphics()
此方法返回 Graphics2D,但此处是出于向后兼容性的考虑。createGraphics 更为方便,因为它被声明为返回 Graphics2D

指定者:
Image 中的 getGraphics
返回:
Graphics2D,可用于绘制此图像。
另请参见:
Graphics, Component.createImage(int, int)

createGraphics

public Graphics2D createGraphics()
创建一个 Graphics2D,可以将它绘制到此 BufferedImage 中。

返回:
Graphics2D,可用于绘制此图像。

getSubimage

public BufferedImage getSubimage(int x,
                                 int y,
                                 int w,
                                 int h)
返回由指定矩形区域定义的子图像。返回的 BufferedImage 与源图像共享相同的数据数组。

参数:
x - 指定矩形区域左上角的 X 坐标
y - 指定矩形区域左上角的 Y 坐标
w - 指定矩形区域的宽度
h - 指定矩形区域的高度
返回:
BufferedImage,它是此 BufferedImage 的子图像。
抛出:
RasterFormatException - 如果指定区域不包含在此 BufferedImage 中。

isAlphaPremultiplied

public boolean isAlphaPremultiplied()
返回是否已预乘以 alpha。如果不存在 alpha,则返回 false

返回:
如果已经预乘以 alpha,则返回 true;否则返回 false

coerceData

public void coerceData(boolean isAlphaPremultiplied)
强制该数据与 isAlphaPremultiplied 变量中指定的状态相匹配。可以将颜色 raster 数据乘以或除以 alpha,如果该数据处于正确状态,则不执行任何操作。

参数:
isAlphaPremultiplied - 如果已经预乘以 alpha,则为 true;否则为 false

toString

public String toString()
返回此 BufferedImage 对象及其值的 String 表示形式。

覆盖:
Object 中的 toString
返回:
BufferedImageString 表示形式。

getSources

public Vector<RenderedImage> getSources()
返回 RenderedImage 对象的 Vector,该对象是此 BufferedImage 图像数据的直接来源,而不是这些直接来源的来源。如果 BufferedImage 没有关于其直接来源的信息,则此方法返回 null。如果 BufferedImage 没有直接来源,则它返回一个空 Vector

指定者:
接口 RenderedImage 中的 getSources
返回:
一个 Vector,它包含此 BufferedImage 对象图像日期的直接来源;如果此 BufferedImage 没有关于其直接来源的信息,则返回 null;如果此 BufferedImage 没有直接来源,则返回一个空 Vector

getPropertyNames

public String[] getPropertyNames()
返回由 getProperty(String) 识别的名称数组;如果没有识别出属性名,则返回 null

指定者:
接口 RenderedImage 中的 getPropertyNames
返回:
一个 String 数组,它包含 getProperty(String) 识别的所有属性名;如果没有识别出属性名,则返回 null

getMinX

public int getMinX()
返回此 BufferedImage 的最小 x 坐标。最小 x 坐标始终为零。

指定者:
接口 RenderedImage 中的 getMinX
返回:
BufferedImage 的最小 x 坐标。

getMinY

public int getMinY()
返回此 BufferedImage 的最小 y 坐标。最小 y 坐标始终为零。

指定者:
接口 RenderedImage 中的 getMinY
返回:
BufferedImage 的最小 y 坐标。

getSampleModel

public SampleModel getSampleModel()
返回与此 BufferedImage 关联的 SampleModel

指定者:
接口 RenderedImage 中的 getSampleModel
返回:
BufferedImageSampleModel

getNumXTiles

public int getNumXTiles()
返回 x 方向的 tile 数。它始终为 1。

指定者:
接口 RenderedImage 中的 getNumXTiles
返回:
x 方向的 tile 数。

getNumYTiles

public int getNumYTiles()
返回 y 方向的 tile 数。它始终为 1。

指定者:
接口 RenderedImage 中的 getNumYTiles
返回:
y 方向的 tile 数。

getMinTileX

public int getMinTileX()
返回 x 方向的最小 tile 索引。它始终为零。

指定者:
接口 RenderedImage 中的 getMinTileX
返回:
x 方向的最小 tile 索引。

getMinTileY

public int getMinTileY()
返回 y 方向的最小 tile 索引。它始终为零。

指定者:
接口 RenderedImage 中的 getMinTileY
返回:
y 方向的最小 tile 索引。

getTileWidth

public int getTileWidth()
返回 tile 宽度(以像素为单位)。

指定者:
接口 RenderedImage 中的 getTileWidth
返回:
tile 宽度(以像素为单位)。

getTileHeight

public int getTileHeight()
返回 tile 高度(以像素为单位)。

指定者:
接口 RenderedImage 中的 getTileHeight
返回:
tile 高度(以像素为单位)。

getTileGridXOffset

public int getTileGridXOffset()
返回 tile 网格相对于原点的 x 偏移量(例如,tile (0, 0) 位置的 x 坐标)。它始终为零。

指定者:
接口 RenderedImage 中的 getTileGridXOffset
返回:
tile 网格的 x 偏移量。

getTileGridYOffset

public int getTileGridYOffset()
返回 tile 网格相对于原点的 y 偏移量(例如,tile (0, 0) 位置的 y 坐标)。它始终为零。

指定者:
接口 RenderedImage 中的 getTileGridYOffset
返回:
tile 网格的 y 偏移量。

getTile

public Raster getTile(int tileX,
                      int tileY)
返回 tile (tileXtileY)。注意,tileXtileY 是 tile 数组中的索引,而不是像素位置。返回的 Raster 是动态的,这意味着如果图像改变,则 Raster 将更新。

指定者:
接口 RenderedImage 中的 getTile
参数:
tileX - tile 数组中所请求的 tile 的 x 索引
tileY - tile 数组中所请求的 tile 的 y 索引
返回:
Raster,它是由参数 tileXtileY 定义的 tile。
抛出:
ArrayIndexOutOfBoundsException - 如果 tileXtileY 都不等于 0

getData

public Raster getData()
以一个大 tile 的形式返回图像。返回的 Raster 是图像数据的副本,图像改变时它不会更新。

指定者:
接口 RenderedImage 中的 getData
返回:
Raster,它是图像数据的副本。
另请参见:
setData(Raster)

getData

public Raster getData(Rectangle rect)
计算并返回 BufferedImage 的一个任意区域。返回的 Raster 是图像数据的副本,图像改变时它不会更新。

指定者:
接口 RenderedImage 中的 getData
参数:
rect - 要返回的 BufferedImage 区域。
返回:
Raster,它是 BufferedImage 指定区域的图像数据的副本
另请参见:
setData(Raster)

copyData

public WritableRaster copyData(WritableRaster outRaster)
计算 BufferedImage 的一个任意矩形区域,并将其复制到指定的 WritableRaster。要计算的区域由指定 WritableRaster 的边界确定。指定 WritableRaster 必须具有与此图像兼容的 SampleModel。如果 outRasternull,则创建一个合适的 WritableRaster

指定者:
接口 RenderedImage 中的 copyData
参数:
outRaster - 保存图像返回部分的 WritableRaster, 或者为 null
返回:
对所提供的或创建的 WritableRaster 的引用。

setData

public void setData(Raster r)
将图像的矩形区域设置为指定 Raster r 的内容,假定该区域与 BufferedImage 处于相同的坐标空间。操作被限制在 BufferedImage 的边界内。

指定者:
接口 WritableRenderedImage 中的 setData
参数:
r - 指定的 Raster
另请参见:
getData(), getData(Rectangle)

addTileObserver

public void addTileObserver(TileObserver to)
添加一个 tile observer。如果该 observer 已经存在,则它接收多个通知。

指定者:
接口 WritableRenderedImage 中的 addTileObserver
参数:
to - 指定的 TileObserver

removeTileObserver

public void removeTileObserver(TileObserver to)
移除一个 tile observer。如果 observer 没有注册,则不发生任何操作。如果 observer 已对多个通知注册,则现在其注册的通知数将减少一个。

指定者:
接口 WritableRenderedImage 中的 removeTileObserver
参数:
to - 指定的 TileObserver

isTileWritable

public boolean isTileWritable(int tileX,
                              int tileY)
返回当前是否为写入签出 tile。

指定者:
接口 WritableRenderedImage 中的 isTileWritable
参数:
tileX - tile 的 x 索引。
tileY - tile 的 y 索引。
返回:
如果为写入签出了由指定索引所指定的 tile,则返回 true;否则,返回 false
抛出:
ArrayIndexOutOfBoundsException - 如果 tileXtileY 都不等于 0

getWritableTileIndices

public Point[] getWritableTileIndices()
返回 Point 对象的数组,它指示为写入签出了哪些 tile。如果没有签出任何 tile,则返回 null

指定者:
接口 WritableRenderedImage 中的 getWritableTileIndices
返回:
一个 Point 数组,它指示为写入签出的 tile;如果没有为写入签出的 tile,则返回 null

hasTileWriters

public boolean hasTileWriters()
返回是否有为写入签出的 tile。语义上等效于
 (getWritableTileIndices() != null)。
 

指定者:
接口 WritableRenderedImage 中的 hasTileWriters
返回:
如果为写入签出了任何 tile,则返回 true;否则返回 false

getWritableTile

public WritableRaster getWritableTile(int tileX,
                                      int tileY)
为写入签出一个 tile。当一个 tile 从没有 writer 变为有一个 writer 时,通知所有已注册的 TileObserver

指定者:
接口 WritableRenderedImage 中的 getWritableTile
参数:
tileX - tile 的 x 索引
tileY - tile 的 y 索引
返回:
一个 WritableRaster,它是为写入而签出的、由指定索引指示的 tile。

releaseWritableTile

public void releaseWritableTile(int tileX,
                                int tileY)
放弃写入一个 tile 的权限。如果调用者继续写入 tile,则结果是不确定的。此方法的调用应该与 getWritableTile(int, int) 的调用成对出现。任何其他用法都会导致不明确的结果。当 tile 从有一个 writer 变为没有 writer 时,通知所有已注册的 TileObserver

指定者:
接口 WritableRenderedImage 中的 releaseWritableTile
参数:
tileX - tile 的 x 索引
tileY - tile 的 y 索引

getTransparency

public int getTransparency()
返回透明度。返回 OPAQUE、BITMASK 或 TRANSLUCENT 中的一个。

指定者:
接口 Transparency 中的 getTransparency
返回:
BufferedImage 的透明度。
从以下版本开始:
1.5
另请参见:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

JavaTM Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策