在我的游戏中,我使用 g2d.scale(scale,scale); 缩放 Graphics2D 对象,以使游戏在所有分辨率下看起来都相同。这样做的问题是图像无法正确旋转,因为它们被视为比实际大小更大或更小。我想知道是否有办法获取绘制图像而不是实际图像的宽度和高度,或者我是否必须根据屏幕的分辨率手动更改宽度和高度变量?
最佳答案
看一下以下函数。
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);
}
关于java - 获取绘制图像的大小,而不是实际图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028965/