简体   繁体   English

如何获得图像的路径?

[英]How do I get a path to an image?

I tried to do this: 我试图这样做:

Path pathForSpriteSheet = Paths.get("/PicFolder/TheSpriteSheet.png");

Then I put it in this method like this: 然后我将其放入这种方法中,如下所示:

loadImage(pathForSpriteSheet);
public void loadImage(BufferedImage image){
    theImage = image;
}

It says "The method loadImage(BufferedImage) in the type BufferedImageLoader is not applicable for the arguments" 它说: “ BufferedImageLoader类型的方法loadImage(BufferedImage)不适用于自变量”

To further what Tom said, you cannot pass a Path variable to the method loadImage when it requires a BufferedImage . 为了进一步说明Tom所说的,当需要BufferedImage时,不能将Path变量传递给loadImage方法。 What you need to do is create a BufferedImage based off of the path you already have and send that to the method. 你需要做的是创建一个BufferedImage基础关你已经有了和发送的方法路径。 Something like: 就像是:

BufferedImage img = ImageIO.read(pathForSpriteSheet.toFile());
loadImage(img);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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