嘿, 每当我试着用ImageIO.createImageInputStream
它只是返回null
没有例外,警告或错误,以得到一个ImageInputStream
对象。我曾尝试将不同的数据类型传递给函数,简单的File
和InputStream
,但都返回null
也。该文档说,如果找不到合适的ImageInputStreamSpi
,那么该函数将返回null
,但该文件是一个bog标准的JPEG格式,并且肯定Java会随服务提供商提供这种开箱即用的格式? 谢谢你的时间。ImageIO.createImageInputStream保持返回NULL
/**
* Reads in an image from a file and returns the image in a
* {@code BufferedImage} object.
*
* @param source the file to create the {@code BufferedImage}
* from.
* @return the {@code BufferedImage} object representing the image
* in {@code source}.
*/
private BufferedImage readImage(File source) {
// There is only one image in this file
final int imageIndex = 0;
BufferedImage image = null;
try {
// Get the ImageReader object for this filetype
Iterator readers =
ImageIO.getImageReaders(source);
ImageReader reader = (ImageReader) readers.next();
// Create an ImageInputStream object from the source image file
ImageInputStream iis = ImageIO.createImageInputStream(source);
// Raises IllegalArgumentException, because iis is null
reader.setInput(iis, true);
// Read the image file
image = reader.read(imageIndex);
} catch (Exception exception) {
exception.printStackTrace();
System.exit(-1);
}
return image;
}
以及清洁你的代码,并张贴在这里,所以我们可以帮助:) – FearUs 2011-02-27 00:13:10
除此之外,你没有回答我的问题,你只要给我一个不同的解决方案,我是已在使用之前,详细如下...我的原始问题,我仍然遇到麻烦,仍然没有答案... – 2011-02-27 09:42:38
我有同样的问题。由于某种原因,它可以在Eclipse中在MacOSX 1.6上运行,但是在Debian Linux环境下生产失败。我的应用程序是建立在Equinox和Jetty servlet容器上的基于OSGI的web应用程序。从我读到目前为止,它似乎与JAI和OSGI(http://stackoverflow.com/questions/1493199/running-jai-in-osgi)有关。但我还没有解决它。 – Christoph 2012-07-08 15:37:53