Java Apache Commons Imaging-将tiff转换为jpg

Java Apache Commons Imaging-将tiff转换为jpg,java,apache-commons,apache-commons-imaging,Java,Apache Commons,Apache Commons Imaging,我需要使用Apache Commons Imaging将tiff图像转换为jpg图像。 我试过,但我不知道如何使用这个库 final BufferedImage image = Imaging.getBufferedImage(new File(image)); final ImageFormat format = ImageFormats.JPEG; final Map<String, Object> params = new HashMap<>(); return I

我需要使用Apache Commons Imaging将
tiff
图像转换为
jpg
图像。 我试过,但我不知道如何使用这个库

final BufferedImage image = Imaging.getBufferedImage(new File(image));
final ImageFormat format = ImageFormats.JPEG;
final Map<String, Object> params = new HashMap<>();
return Imaging.writeImageToBytes(image, format, params);
final BufferedImage image=Imaging.getBufferedImage(新文件(图像));
最终图像格式=ImageFormats.JPEG;
final Map params=new HashMap();
返回Imaging.writeImageToBytes(图像、格式、参数);
其中,
image
是要转换的
tiff
文件,但我得到

org.apache.commons.imaging.ImageWriteException:无法写入此图像格式(Jpeg自定义)


我不明白我做错了什么,有人能帮我吗?

尝试使用java AWT:

   import java.awt.Color;
   import java.awt.image.BufferedImage;
   import java.io.File;
   import java.io.IOException;
   import javax.imageio.ImageIO;
和代码:

  // TIFF image file read
  BufferedImage tiffImage = ImageIO.read(new File("tiff-image.tiff"));
  // Prepare the image before writing - with same dimensions
  BufferedImage jpegImage = new BufferedImage(
          tiffImage.getWidth(),
          tiffImage.getHeight(), 
          BufferedImage.TYPE_INT_RGB);
  // Draw image from original TIFF to the new JPEG image
  jpegImage.createGraphics().drawImage(tiffImage, 0, 0, Color.WHITE, null);
  // Write the image as JPEG to disk
  ImageIO.write(jpegImage, "jpg", new File("jpeg-image.jpg"));

我的猜测是,使用ApacheCommons Imaging可能无法(不受支持)进行这种转换。你愿意接受其他选择吗?您的项目限制是什么?我只需要一个库来进行转换并在开放jdk上工作(我现在在8上)。我正在尝试弄清楚Apache Commons Imaging是否可以做到这一点,但显然不行。所以,一切正常(JAI除外)的ApacheCommonsImaging都有。谢谢!它起作用了!但是,我必须安装此插件才能使用ImageIO读取tiff图像: