JavaTM Platform
Standard Ed. 6

java.awt
类 GraphicsConfiguration

java.lang.Object
  继承者 java.awt.GraphicsConfiguration

public abstract class GraphicsConfiguration
     
extends Object

GraphicsConfiguration 类描述图形目标(如打印机或监视器)的特征。有许多与单一图形设备关联的 GraphicsConfiguration 对象,表示不同的绘图模式或能力。相应的本机结构也将因平台而异。例如,在 X11 窗口系统上,每个可视组件都是一个不同的 GraphicsConfiguration。在 Microsoft Windows 系统上,GraphicsConfiguration 表示当前分辨率和颜色深度下可用的 PixelFormat。

在虚拟设备多屏幕环境中(其中桌面区域可以跨越多个物理屏幕设备),GraphicsConfiguration 对象的边界与虚拟坐标系相关。当设置组件的位置时,使用 getBounds 来获得所需 GraphicsConfiguration 的边界和 GraphicsConfiguration 坐标位置的偏移量,以下代码示例给出了说明:

      Frame f = new Frame(gc);  // where gc is a GraphicsConfiguration
      Rectangle bounds = gc.getBounds();
      f.setLocation(10 + bounds.x, 10 + bounds.y); 

要确定环境是否为虚拟设备环境,可以对系统中的所有 GraphicsConfiguration 对象调用 getBounds。如果所有返回的边界原点都不是 (0, 0),则环境为虚拟设备环境。

也可以使用 getBounds 来确定虚拟设备的边界。为此,首先要对系统中的所有 GraphicsConfiguration 对象调用 getBounds。然后计算调用 getBounds 返回的所有边界的并集。该并集就是虚拟设备的边界。以下代码示例可计算虚拟设备的边界。

      Rectangle virtualBounds = new Rectangle();
      GraphicsEnvironment ge = GraphicsEnvironment.
              getLocalGraphicsEnvironment();
      GraphicsDevice[] gs =
              ge.getScreenDevices();
      for (int j = 0; j < gs.length; j++) { 
          GraphicsDevice gd = gs[j];
          GraphicsConfiguration[] gc =
              gd.getConfigurations();
          for (int i=0; i < gc.length; i++) {
              virtualBounds =
                  virtualBounds.union(gc[i].getBounds());
          }
      } 

另请参见:
Window, Frame, GraphicsEnvironment, GraphicsDevice

构造方法摘要
protected GraphicsConfiguration()
          这是一个不可直接实例化的抽象类。
 
方法摘要
abstract  BufferedImage createCompatibleImage(int width, int height)
          返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage
 BufferedImage createCompatibleImage(int width, int height, int transparency)
          返回一个支持指定透明度,并且数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage
 VolatileImage createCompatibleVolatileImage(int width, int height)
          返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
 VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps)
          返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容并使用指定图像能力的 VolatileImage
 VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps, int transparency)
          返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容并使用指定图像能力和透明度值的 VolatileImage
 VolatileImage createCompatibleVolatileImage(int width, int height, int transparency)
          返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
abstract  Rectangle getBounds()
          返回 GraphicsConfiguration 在设备坐标中的边界。
 BufferCapabilities getBufferCapabilities()
          返回此 GraphicsConfiguration 的缓冲区能力。
abstract  ColorModel getColorModel()
          返回与此 GraphicsConfiguration 关联的 ColorModel
abstract  ColorModel getColorModel(int transparency)
          返回与此 GraphicsConfiguration 关联并支持指定透明度的 ColorModel
abstract  AffineTransform getDefaultTransform()
          返回此 GraphicsConfiguration 的默认 AffineTransform
abstract  GraphicsDevice getDevice()
          返回与此 GraphicsConfiguration 关联的 GraphicsDevice
 ImageCapabilities getImageCapabilities()
          返回此 GraphicsConfiguration 的图像能力。
abstract  AffineTransform getNormalizingTransform()
          返回可与 GraphicsConfiguration 的默认 AffineTransform 连接的 AffineTransform,从而用户空间的 72 单位等于设备空间的 1 英寸。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

GraphicsConfiguration

protected GraphicsConfiguration()
这是一个不可直接实例化的抽象类。必须从合适的工厂或查询方法中获取实例。

另请参见:
GraphicsDevice.getConfigurations(), GraphicsDevice.getDefaultConfiguration(), GraphicsDevice.getBestConfiguration(java.awt.GraphicsConfigTemplate), Graphics2D.getDeviceConfiguration()
方法详细信息

getDevice

public abstract GraphicsDevice getDevice()
返回与此 GraphicsConfiguration 关联的 GraphicsDevice

返回:
一个与此 GraphicsConfiguration 关联的 GraphicsDevice 对象。

createCompatibleImage

public abstract BufferedImage createCompatibleImage(int width,
                                                    int height)
返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage。此方法与设备的内存映射无关。返回 BufferedImage 的数据布局和颜色模型与本机设备配置最接近,因此最适合于位图传输 (blitted) 到此设备上。

参数:
width - 返回的 BufferedImage 宽度
height - 返回的 BufferedImage 高度
返回:
一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage

createCompatibleImage

public BufferedImage createCompatibleImage(int width,
                                           int height,
                                           int transparency)
返回一个支持指定透明度,并且数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage。此方法与设备的内存映射无关。返回 BufferedImage 的数据布局和颜色模型最适合于位图传输 (blitted) 到利用此 GraphicsConfiguration 的设备上。

参数:
width - 返回的 BufferedImage 宽度
height - 返回的 BufferedImage 高度
transparency - 指定的透明度模式
返回:
一个数据布局和颜色模型与此 GraphicsConfiguration 兼容且支持指定透明度的 BufferedImage
抛出:
IllegalArgumentException - 如果透明度不是一个有效值
另请参见:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

createCompatibleVolatileImage

public VolatileImage createCompatibleVolatileImage(int width,
                                                   int height)
返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage。返回的 VolatileImage 可能有最适合于底层图形设备的存储数据,因此可能从特定于平台的呈现加速中受益。

参数:
width - 返回的 VolatileImage 宽度
height - 返回的 VolatileImage 高度
返回:
一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
从以下版本开始:
1.4
另请参见:
Component.createVolatileImage(int, int)

createCompatibleVolatileImage

public VolatileImage createCompatibleVolatileImage(int width,
                                                   int height,
                                                   int transparency)
返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage。返回的 VolatileImage 可能有最适合于底层图形设备的存储数据,因此可能从特定于平台的呈现加速中受益。

参数:
width - 返回的 VolatileImage 宽度
height - 返回的 VolatileImage 高度
transparency - 指定的透明度模式
返回:
一个数据和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
抛出:
IllegalArgumentException - 如果透明度不是一个有效值
从以下版本开始:
1.5
另请参见:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT, Component.createVolatileImage(int, int)

createCompatibleVolatileImage

public VolatileImage createCompatibleVolatileImage(int width,
                                                   int height,
                                                   ImageCapabilities caps)
                                            throws AWTException
返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容并使用指定图像能力的 VolatileImage。如果该 caps 参数为 null,则有效地忽略它,此方法还将创建一个 VolatileImage,而不考虑 ImageCapabilities 约束。 返回 VolatileImage 的数据布局和颜色模型与本机设备配置最接近,因此最适合于位图传输 (blitted) 到此设备上。

参数:
width - 返回的 VolatileImage 宽度
height - 返回的 VolatileImage 高度
caps - 图像能力
返回:
一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
抛出:
AWTException - 如果此图形配置无法满足提供的图像能力
从以下版本开始:
1.4

createCompatibleVolatileImage

public VolatileImage createCompatibleVolatileImage(int width,
                                                   int height,
                                                   ImageCapabilities caps,
                                                   int transparency)
                                            throws AWTException
返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容并使用指定图像能力和透明度值的 VolatileImage。如果该 caps 参数为 null,则有效地忽略它,此方法还将创建一个 VolatileImage,而不考虑 ImageCapabilities 约束。 返回 VolatileImage 的数据布局和颜色模型与本机设备配置最接近,因此最适合于位图传输 (blitted) 到此设备上。

参数:
width - 返回的 VolatileImage 宽度
height - 返回的 VolatileImage 高度
caps - 图像能力
transparency - 指定的透明度模式
返回:
一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 VolatileImage
抛出:
IllegalArgumentException - 如果透明度不是一个有效值
AWTException - 如果此图形配置无法满足提供的图像能力
从以下版本开始:
1.5
另请参见:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT, Component.createVolatileImage(int, int)

getColorModel

public abstract ColorModel getColorModel()
返回与此 GraphicsConfiguration 关联的 ColorModel

返回:
一个与此 GraphicsConfiguration 关联的 ColorModel 对象。

getColorModel

public abstract ColorModel getColorModel(int transparency)
返回与此 GraphicsConfiguration 关联并支持指定透明度的 ColorModel

参数:
transparency - 指定的透明度模式
返回:
一个与此 GraphicsConfiguration 关联并支持指定透明度的 ColorModel 对象;如果透明度不是一个有效值,则返回 null。
另请参见:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

getDefaultTransform

public abstract AffineTransform getDefaultTransform()
返回此 GraphicsConfiguration 的默认 AffineTransform。此 AffineTransform 通常是大多数正常屏幕的 Identity 转换。默认的 AffineTransform 将坐标映射到设备上:72 用户空间坐标单位在尺度上近似于设备空间的 1 英寸。标准化的转换可使映射关系更准确。坐标空间中默认 AffineTransform 为屏幕和打印机设备定义的坐标如下:原点在设备目标区域的左上角,X 坐标方向向右,Y 坐标方向向下。对于与此设备无关的图像缓冲区,如那些非 createCompatibleImage 创建的缓冲区,此 AffineTransform 即为 Identity 转换。

返回:
GraphicsConfiguration 的默认 AffineTransform

getNormalizingTransform

public abstract AffineTransform getNormalizingTransform()
返回可与 GraphicsConfiguration 的默认 AffineTransform 连接的 AffineTransform,从而用户空间的 72 单位等于设备空间的 1 英寸。

对于特定 Graphics2D g,可使用以下伪代码重新设置转换来创建这种映射关系:

      GraphicsConfiguration gc = g.getDeviceConfiguration();

      g.setTransform(gc.getDefaultTransform());
      g.transform(gc.getNormalizingTransform());
 
注意,有时此 AffineTransform 是诸如打印机或图元文件输出的标识,并且此 AffineTransform 只与底层系统提供的信息一样准确。对于与设备没有关联的图像缓冲区,如那些非 createCompatibleImage 创建的缓冲区,因为没有有效的距离尺度,此 AffineTransform 即为 Identity 转换。

返回:
一个连接默认 AffineTransformAffineTransform,从而用户空间的 72 单位映射为设备空间的 1 英寸。

getBounds

public abstract Rectangle getBounds()
返回 GraphicsConfiguration 在设备坐标中的边界。在虚拟设备的多屏环境中,边界可以有负 X 或 Y 原点。

返回:
GraphicsConfiguration 覆盖的区域边界。
从以下版本开始:
1.3

getBufferCapabilities

public BufferCapabilities getBufferCapabilities()
返回此 GraphicsConfiguration 的缓冲区能力。

返回:
此图形配置对象的缓冲区能力
从以下版本开始:
1.4

getImageCapabilities

public ImageCapabilities getImageCapabilities()
返回此 GraphicsConfiguration 的图像能力。

返回:
此图形配置对象的图像能力
从以下版本开始:
1.4

JavaTM Platform
Standard Ed. 6

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

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