简体   繁体   English

Java ImageIO:无法读取输入文件

[英]Java ImageIO: can't read input file

I don't know why this isn't working, but the program says it can't read the input file. 我不知道为什么这不起作用,但程序说它无法读取输入文件。 This is also being run in Ubuntu, by the way: 顺便说一句,这也是在Ubuntu中运行的:

Here is the sample code: 以下是示例代码:

URI url = new URI("images/GUI/TitleScreen.PNG");
File file = new File(url.toString());           
bg = new ImageBackground(ImageIO.read(file));

The directory is located in the bin folder and src folder of the program as well. 该目录也位于程序的bin文件夹和src文件夹中。

What if you instead got your image as a stream from a resource? 如果您将图像作为资源中的流获取,该怎么办? eg, 例如,

String imgPath = "images/GUI/TitleScreen.PNG";
BufferedImage buffImage = ImageIO.read(getClass().getResourceAsStream(imgPath));
bg = new ImageBackground(buffImage);

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

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