簡體   English   中英

獲取繪制圖像的大小,而不是實際的

[英]Get the size of the drawn image, not the actual one

在我的游戲中,我使用g2d.scale(scale, scale);縮放Graphics2D對象g2d.scale(scale, scale); 使游戲在所有分辨率下看起來都一樣 問題在於圖像將無法正確旋轉,因為它們被視為比實際大小更大或更小的圖像。 我想知道是否有一種方法可以獲取繪制圖像的寬度和高度而不是實際圖像,或者是否必須根據屏幕的分辨率手動更改寬度和高度變量?

看一下下面的功能。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM