【发布时间】:2013-06-06 09:48:49
【问题描述】:
在我的游戏中,我使用 g2d.scale(scale, scale); 缩放 Graphics2D 对象,以使游戏在所有分辨率下看起来都一样。这样做的问题是图像不会正确旋转,因为它们被视为比实际更大或更小。我想知道是否有办法获取绘制图像的宽度和高度而不是实际图像,或者我是否必须根据屏幕的分辨率手动更改宽度和高度变量?
【问题讨论】:
标签: java graphics size awt resolution
在我的游戏中,我使用 g2d.scale(scale, scale); 缩放 Graphics2D 对象,以使游戏在所有分辨率下看起来都一样。这样做的问题是图像不会正确旋转,因为它们被视为比实际更大或更小。我想知道是否有办法获取绘制图像的宽度和高度而不是实际图像,或者我是否必须根据屏幕的分辨率手动更改宽度和高度变量?
【问题讨论】:
标签: java graphics size awt resolution
看看下面的函数。
public void picture(File pictureFile) {
Image theImage = null;
try {
theImage = getToolkit().getImage(pictureFile.getAbsolutePath());
getToolkit().prepareImage(theImage, -1, -1, this);
while ((getToolkit().checkImage(theImage, -1, -1, this) & this.ALLBITS) == 0) {
}
} catch (Exception e) {
}
// these lines will return Height and Width of image
theImage.getWidth(this);
theImage.getHeight(this);
}
【讨论】: