ImageIO.read() 无限循环 [英] ImageIO.read() infinite loop
本文介绍了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 和文件,但没有任何效果.
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() 无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文