简体   繁体   中英

javaFx Image Height and Width got backwards?

I am making a game in javaFx. The way entities in my game is rendered is dependent on one of their fields called "angle", like this:

        gc.save();
        gc.transform(new Affine(new Rotate(angle, getCenterX(), getCenterY())));
        gc.drawImage(image, x, y);
        gc.restore();

"Gc" is the GraphicsContext. The getCenter methods will use the height and width of the images. However, the images are not rendered properly. I ran some tests and found that when I use the get Width method, it actually returns the height of the image. When I call the get Height method, it returns the width. My guess is that it's because the png images I use have been rotated 90 degrees in respect to their original state. However, when I go to preview and look at their size, it seems that everything is fine. I tried duplicating the images, but it doesn't really work. Any ideas how to fix this? I don't have a verifiable code example because I believe this question is more related to properties of png files and javaFx's Image methods than my program's logic. 在此处输入图片说明 在此处输入图片说明


Here is the verifiable code example:

import javafx.embed.swing.JFXPanel;
import javafx.scene.image.Image;

public class TestImage {    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        JFXPanel jfxPanel = new JFXPanel();
        Image BLUE01 = new Image("/blue01.png");
        System.out.println("height : "+ BLUE01.getHeight());
        System.out.println("wdith : "+ BLUE01.getWidth());
    }
}

And here is the image: 在此处输入图片说明

看来问题出在我的代码而不是我的IDE上。。。事实证明,在我在资源文件夹中编辑或添加图像后,我需要在Eclipse中单击“刷新”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM