java.lang.Objectjava.awt.Image
java.awt.image.BufferedImage
public class BufferedImage
      BufferedImage 子类描述具有可访问图像数据缓冲区的 Image。BufferedImage 由图像数据的 ColorModel 和 Raster 组成。Raster 的 SampleModel 中 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) 构造一个具有指定 ColorModel 和 Raster 的新 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 对象(比如 ComponentColorModel 和 DirectColorModel)表示 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 ( tileX, tileY)。 |  
    
  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 |  
    
| 字段详细信息 | 
|---|
public static final int TYPE_CUSTOM
public static final int TYPE_INT_RGB
DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_INT_ARGB
DirectColorModel。认为此图像中的颜色数据没有预乘以 alpha。当使用此类型作为 
    BufferedImage 构造方法的 
    imageType 参数时,所创建的图像与 JDK1.1 和更早期版本中创建的图像一致。 
    
public static final int TYPE_INT_ARGB_PRE
DirectColorModel。认为此图像中的颜色数据已预乘以 alpha。 
    
public static final int TYPE_INT_BGR
DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_3BYTE_BGR
ComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_4BYTE_ABGR
ComponentColorModel。认为此图像中的颜色数据没有预乘以 alpha。按照每个像素中字节地址从低到高的顺序 A、B、G、R 将字节数据插入单个字节数组中。 
    
public static final int TYPE_4BYTE_ABGR_PRE
ComponentColorModel。认为此图像中的颜色数据已预乘以 alpha。按照每个像素中字节地址从低到高的顺序 A、B、G、R 将字节数据插入单个字节数组中。 
    
public static final int TYPE_USHORT_565_RGB
DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_USHORT_555_RGB
DirectColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_BYTE_GRAY
ColorSpace 的 
    ComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_USHORT_GRAY
ColorSpace 的 
    ComponentColorModel。当具有透明 alpha 的数据存储在此类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha,如 
    AlphaComposite 文档中的描述。 
    
public static final int TYPE_BYTE_BINARY
IndexColorModel。当此类型用作 
    BufferedImage 构造方法(带 
    imageType 参数而不是 
    ColorModel 参数)的 
    imageType 参数时,创建一个 1 位图像,且其 
    IndexColorModel 具有默认 sRGB 
    ColorSpace 中的两种颜色:{0, 0, 0} 和 {255, 255, 255}。 
     每个像素 2 位或 4 位的图像可以通过 BufferedImage 构造方法构造,该构造方法带一个 ColorModel 参数,这通过提供一个具有合适映射大小的 ColorModel 实现。 
 每个像素 8 位的图像应该使用 TYPE_BYTE_INDEXED 或 TYPE_BYTE_GRAY 图像类型,具体取决于它们的 ColorModel。 
 当颜色数据存储在此类型的图像中时,由 IndexColorModel 确定 colormap 中最接近的颜色,并存储得到的索引。根据 IndexColorModel colormap 中的颜色,可以得到 alpha 分量或颜色分量的近似值及丢失的 alpha 或颜色分量。 
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 或颜色分量。 
| 构造方法详细信息 | 
|---|
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
     
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
     public BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)
ColorModel 和 
    Raster 的新 
    BufferedImage。如果 
    Raster 的 
    SampleModel 中 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 - 如果 
      Raster 的 
      SampleModel 中 band 的数量和类型与 
      ColorModel(表示其颜色和 alpha 分量)所要求的数量和类型不匹配。 
     IllegalArgumentException - 如果 
      raster 与 
      cm 不一致
     ColorModel, 
      Raster, 
      WritableRaster
     | 方法详细信息 | 
|---|
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。 
    
RenderedImage 中的 
      getColorModel
     BufferedImage 的 
      ColorModel。
     public WritableRaster getRaster()
WritableRaster。 
    
BufferedImage 的 
      WriteableRaster。
     public WritableRaster getAlphaRaster()
WritableRaster,它使用支持单独空间 alpha 通道的 
    ColorModel 对象(比如 
    ComponentColorModel 和 
    DirectColorModel)表示 
    BufferedImage 对象的 alpha 通道。如果此图像中没有与 
    ColorModel 关联的 alpha 通道,则返回 
    null。此方法假定 
    IndexColorModel 之外的所有 
    ColorModel 对象都具有一个单独的 alpha 通道(如果 
    ColorModel 支持 alpha),该通道存储为图像数据的最后一个 band。如果该图像使用查找表中一个具有 alpha 的 
    IndexColorModel,则此方法返回 
    null