Java ImageIO:无法读取输入文件 [英] Java ImageIO: can't read input file

查看:328
本文介绍了Java ImageIO:无法读取输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么这不起作用,但程序说它无法读取输入文件。顺便说一下,这也在Ubuntu中运行:

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:

以下是示例代码:

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

该目录也位于程序的bin文件夹和src文件夹中。

The directory is located in the bin folder and src folder of the program as well.

推荐答案

如果您将图像作为资源中的流获取,该怎么办?例如,

What if you instead got your image as a stream from a resource? e.g.,

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

这篇关于Java ImageIO:无法读取输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆