我正在阅读图像并想要获取图像格式。
private static String getFormatName(Object o) {
try {
// Create an image input stream on the image
ImageInputStream iis = ImageIO.createImageInputStream(o);
// Find all image readers that recognize the image format
Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
if (!iter.hasNext()) {
// No readers found
return null;
}
// Use the first reader
ImageReader reader = (ImageReader)iter.next();
String name = reader.getFormatName();
iis.close();
return name;
} catch (IOException e) {
}
// The image could not be read
return null;
}
当我执行它时,我得到以下异常,
java.lang.IllegalArgumentException: image == null!