java.lang.Object
java.awt.GraphicsConfiguration
GraphicsConfiguration类描述了图形目标(如打印机或监视器)的特征。可以有许多与单个图形设备关联的GraphicsConfiguration对象,表示不同的绘图模式或功能。相应的本机结构会因平台而异。例如,在X11窗口系统中,每个视觉是一个不同的GraphicsConfiguration。在Microsoft Windows上,GraphicsConfiguration代表当前分辨率和颜色深度中可用的像素格式。
在虚拟设备多屏环境中,桌面区域可能跨越多个物理屏幕设备,GraphicsConfiguration对象的边界是相对于虚拟坐标系的。当设置组件的位置时,请使用getBounds获取所需GraphicsConfiguration的边界,并使用GraphicsConfiguration的坐标偏移位置,如下面的代码示例所示:
Frame f = new Frame(gc); // 其中gc是一个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());
}
}
- 参见:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateCompatibleImage(int width, int height) 返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的BufferedImage。createCompatibleImage(int width, int height, int transparency) 返回一个支持指定透明度的BufferedImage,并且具有与此GraphicsConfiguration兼容的数据布局和颜色模型。createCompatibleVolatileImage(int width, int height) 返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。createCompatibleVolatileImage(int width, int height, int transparency) 返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。createCompatibleVolatileImage(int width, int height, ImageCapabilities caps) 返回一个使用指定图像能力的与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。createCompatibleVolatileImage(int width, int height, ImageCapabilities caps, int transparency) 返回一个使用指定图像能力和透明度值的与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。abstract Rectangle返回设备坐标中GraphicsConfiguration的边界。返回此GraphicsConfiguration的缓冲能力。abstract ColorModel返回与此GraphicsConfiguration关联的ColorModel。abstract ColorModelgetColorModel(int transparency) 返回支持指定透明度的与此GraphicsConfiguration关联的ColorModel。abstract AffineTransform返回此GraphicsConfiguration的默认AffineTransform。abstract GraphicsDevice返回与此GraphicsConfiguration关联的GraphicsDevice。返回此GraphicsConfiguration的图像能力。abstract AffineTransform返回一个AffineTransform,可与GraphicsConfiguration的默认AffineTransform连接,使用户空间中的72个单位等于设备空间中的1英寸。boolean返回此GraphicsConfiguration是否支持PERPIXEL_TRANSLUCENT类型的半透明。
-
Constructor Details
-
GraphicsConfiguration
protected GraphicsConfiguration()这是一个抽象类,不能直接实例化。必须从适当的工厂或查询方法获取实例。- 参见:
-
-
Method Details
-
getDevice
返回与此GraphicsConfiguration关联的GraphicsDevice。- 返回:
-
与此
GraphicsConfiguration关联的GraphicsDevice对象。
-
createCompatibleImage
返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的BufferedImage。此方法与内存映射设备无关。返回的BufferedImage具有最接近本机设备配置的布局和颜色模型,因此可以最优地复制到此设备。- 参数:
-
width- 返回的BufferedImage的宽度 -
height- 返回的BufferedImage的高度 - 返回:
-
一个数据布局和颜色模型与此
GraphicsConfiguration兼容的BufferedImage。
-
createCompatibleImage
返回一个支持指定透明度的BufferedImage,并且具有与此GraphicsConfiguration兼容的数据布局和颜色模型。此方法与内存映射设备无关。返回的BufferedImage具有可以最优地复制到具有此GraphicsConfiguration的设备的布局和颜色模型。- 参数:
-
width- 返回的BufferedImage的宽度 -
height- 返回的BufferedImage的高度 -
transparency- 指定的透明度模式 - 返回:
-
一个数据布局和颜色模型与此
GraphicsConfiguration兼容并且还支持指定透明度的BufferedImage。 - 抛出:
-
IllegalArgumentException- 如果透明度不是有效值 - 参见:
-
createCompatibleVolatileImage
返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。返回的VolatileImage可能具有针对底层图形设备进行优化存储的数据,因此可能受益于特定平台的渲染加速。- 参数:
-
width- 返回的VolatileImage的宽度 -
height- 返回的VolatileImage的高度 - 返回:
-
一个数据布局和颜色模型与此
GraphicsConfiguration兼容的VolatileImage。 - 自:
- 1.4
- 参见:
-
createCompatibleVolatileImage
返回一个与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage。返回的VolatileImage可能具有针对底层图形设备进行优化存储的数据,因此可能受益于特定平台的渲染加速。- 参数:
-
width- 返回的VolatileImage的宽度 -
height- 返回的VolatileImage的高度 -
transparency- 指定的透明度模式 - 返回:
-
一个
VolatileImage,其数据布局和颜色模型与此GraphicsConfiguration兼容。 - 抛出:
-
IllegalArgumentException- 如果透明度不是有效值 - 自版本:
- 1.5
- 参见:
-
createCompatibleVolatileImage
public VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps) throws AWTException 返回一个具有与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage,使用指定的图像能力。如果caps参数为null,则会被忽略,此方法将创建一个VolatileImage,而不考虑ImageCapabilities的约束。返回的VolatileImage具有与本机设备配置最接近的布局和颜色模型,因此可以最优地传输到此设备。- 参数:
-
width- 返回的VolatileImage的宽度 -
height- 返回的VolatileImage的高度 -
caps- 图像能力 - 返回:
-
一个
VolatileImage,其数据布局和颜色模型与此GraphicsConfiguration兼容。 - 抛出:
-
AWTException- 如果提供的图像能力无法满足此图形配置 - 自版本:
- 1.4
-
createCompatibleVolatileImage
public VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps, int transparency) throws AWTException 返回一个具有与此GraphicsConfiguration兼容的数据布局和颜色模型的VolatileImage,使用指定的图像能力和透明度值。如果caps参数为null,则会被忽略,此方法将创建一个VolatileImage,而不考虑ImageCapabilities的约束。返回的VolatileImage具有与本机设备配置最接近的布局和颜色模型,因此可以最优地传输到此设备。- 参数:
-
width- 返回的VolatileImage的宽度 -
height- 返回的VolatileImage的高度 -
caps- 图像能力 -
transparency- 指定的透明度模式 - 返回:
-
一个
VolatileImage,其数据布局和颜色模型与此GraphicsConfiguration兼容。 - 抛出:
-
IllegalArgumentException- 如果透明度不是有效值 -
AWTException- 如果提供的图像能力无法满足此图形配置 - 自版本:
- 1.5
- 参见:
-
getColorModel
返回与此GraphicsConfiguration关联的ColorModel。- 返回:
-
与此
GraphicsConfiguration关联的ColorModel对象。
-
getColorModel
返回支持指定透明度的此GraphicsConfiguration关联的ColorModel。- 参数:
-
transparency- 指定的透明度模式 - 返回:
-
与此
GraphicsConfiguration关联且支持指定透明度的ColorModel对象,如果透明度不是有效值,则返回null。 - 参见:
-
getDefaultTransform
返回此GraphicsConfiguration的默认AffineTransform。对于大多数普通屏幕,此AffineTransform通常是标识变换。默认的AffineTransform将坐标映射到设备上,使得72个用户空间坐标单位在设备空间中大约测量1英寸。标准化变换可用于使此映射更加精确。由默认AffineTransform定义的屏幕和打印机设备的坐标空间中的坐标具有原点位于设备目标区域的左上角,其中X坐标向右增加,Y坐标向下增加。对于与设备不相关的图像缓冲区,例如未通过createCompatibleImage创建的图像,此AffineTransform是标识变换。- 返回:
-
此
GraphicsConfiguration的默认AffineTransform。
-
getNormalizingTransform
返回一个AffineTransform,可与GraphicsConfiguration的默认AffineTransform连接,以便使用户空间中的72个单位等于设备空间中的1英寸。对于特定的
Graphics2D,g,可以通过以下伪代码重置变换以创建这样的映射:GraphicsConfiguration gc = g.getDeviceConfiguration(); g.setTransform(gc.getDefaultTransform()); g.transform(gc.getNormalizingTransform());请注意,有时此AffineTransform是标识,例如对于打印机或元文件输出,此AffineTransform仅与底层系统提供的信息一样准确。对于与设备不相关的图像缓冲区,例如未通过createCompatibleImage创建的图像,此AffineTransform是标识变换,因为没有有效的距离测量。- 返回:
-
一个
AffineTransform,可连接到默认AffineTransform,以便使用户空间中的72个单位映射到设备空间中的1英寸。
-
getBounds
返回设备坐标中此GraphicsConfiguration的边界。在具有虚拟设备的多屏幕环境中,边界可以具有负X或Y原点。- 返回:
-
此
GraphicsConfiguration覆盖的区域的边界。 - 自版本:
- 1.3
-
getBufferCapabilities
返回此GraphicsConfiguration的缓冲能力。- 返回:
- 此图形配置对象的缓冲能力
- 自版本:
- 1.4
-
getImageCapabilities
返回此GraphicsConfiguration的图像能力。- 返回:
- 此图形配置对象的图像能力
- 自版本:
- 1.4
-
isTranslucencyCapable
public boolean isTranslucencyCapable()返回此GraphicsConfiguration是否支持PERPIXEL_TRANSLUCENT类型的透明度。- 返回:
- 给定的GraphicsConfiguration是否支持透明效果。
- 自版本:
- 1.7
- 参见:
-