我正在尝试将 JPEG2000 (.jp2) 图像转换为其他格式(JPEG 或 PNG),因此我尝试使用 writejavax.imageio
封装方法。这适用于其他格式(例如 JPEG 到 PNG),但当涉及 JPEG2000(或 TIFF)时,它会引发异常。谁能告诉我输入图像的可能格式是什么?
Exception in thread "main" java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(ImageIO.java:1457)
at javax.imageio.ImageIO.write(ImageIO.java:1565)
at decodeincodeimages.AndroidInterface.convertFormat(AndroidInterface.java:199)
at Main_package.Execute.main(Execute.java:69)
Java Result: 1
这是方法:
public static boolean convertFormat(String inputImagePath,
String outputImagePath, String formatName) throws IOException {
FileInputStream inputStream = new FileInputStream(inputImagePath);
FileOutputStream outputStream = new FileOutputStream(outputImagePath);
// reads input image from file
BufferedImage inputImage = ImageIO.read(inputStream);
// writes to the output image in specified format
boolean result = ImageIO.write(inputImage, formatName, outputStream);
// needs to close the streams
outputStream.close();
inputStream.close();
return result;
}
我这样称呼它:
System.out.println(AndroidInterface.convertFormat("g:\\picture.jp2","g:\\conv.gif", "gif"));