【问题标题】:Get the size of the drawn image, not the actual one获取绘制图像的大小,而不是实际的大小
【发布时间】:2013-06-06 09:48:49
【问题描述】:

在我的游戏中,我使用 g2d.scale(scale, scale); 缩放 Graphics2D 对象,以使游戏在所有分辨率下看起来都一样。这样做的问题是图像不会正确旋转,因为它们被视为比实际更大或更小。我想知道是否有办法获取绘制图像的宽度和高度而不是实际图像,或者我是否必须根据屏幕的分辨率手动更改宽度和高度变量?

【问题讨论】:

    标签: java graphics size awt resolution


    【解决方案1】:

    看看下面的函数。

    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);
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-15
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多