如何在 Java 中实现 jpeg-lossess?
ImageWriter writer = (ImageWriter) ImageIO.getImageWritersByFormatName("JPEG-LS").next();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType("JPEG-LS");
writer.setOutput(ImageIO.createImageOutputStream(new File("C:\\Users\\RileyRen\\Desktop\\123.jpg")));
writer.write(null, new IIOImage(subBufferedImage, null, null), param);
会抛出异常:
Exception in thread "main"
java.lang.IllegalArgumentException: Unknown compression type!
at javax.imageio.ImageWriteParam.setCompressionType(ImageWriteParam.java:1041)
at com.demandforce.ImageCrop.main(ImageCrop.java:59)
唯一的param.getCompressionTypes()
打印[JPEG]
。
使用JAI
(版本 1.1.3):
PlanarImage input = JAI.create("fileload", "C:\\Users\\RileyRen\\Desktop\\test.jpg");
ParameterBlock pb = new ParameterBlock();
pb.addSource(input);
pb.add(x);
pb.add(y);
pb.add(width);
pb.add(height);
PlanarImage output = JAI.create("crop",pb,null);
JAI.create("filestore",output,"C:\\Users\\RileyRen\\Desktop\\123.jpg","JPEG-LS");
也抛出异常:
Exception in thread "main"
java.lang.IllegalArgumentException: FileStore The specified format has no associated registered ImageCodec.
at javax.media.jai.JAI.createNS(JAI.java:1087)
at javax.media.jai.JAI.create(JAI.java:973)
at javax.media.jai.JAI.create(JAI.java:1621)
at com.demandforce.ImageCrop.main(ImageCrop.java:103)
你能写一个样本吗?