本文介绍了ImageIO.read()无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ImageIO.read()似乎陷入了无限循环.
ImageIO.read() just seems to be stuck in an infinite loop.
我的代码:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Texture {
BufferedImage _img;
public Texture(String path) {
try {
_img = ImageIO.read(new File(path));
} catch (final IOException e) {
e.printStackTrace();
}
}
}
其他班级:
private Texture _tex;
_tex = new Texture("/res/img.png");
我尝试通过该URL和File加载图像,但没有效果.
I have tried loading the image this URL and File, none works.
在Mac上,我正在使用eclipse,并且与LWJGL 3有任何关系.
I am using eclipse, on a mac, and I am using LWJGL 3 if that has anything to do with anything.
希望您能帮助我! :-)
Hope you can help me! :-)
推荐答案
而不是使用文件,请尝试使用像这样的输入流:
Instead of using a File, try using an input stream like this:
InputStream stream = Texture.class.getResourceAsStream(path);
_img = ImageIO.read(stream);
我实际上遇到了类似的问题,但这与BufferedImages的创建有关.
I'm actually experiencing a similar issue, but it's related to the creation of BufferedImages.
这篇关于ImageIO.read()无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!