我正在使用java压缩图像。
我想在jpeg2000中压缩图像无损。
请建议解决方案。
File imageFile = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg");
File compressedImageFile = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\decompjai.jpg");
InputStream is = new FileInputStream(imageFile);
OutputStream os = new FileOutputStream(compressedImageFile);
BufferedImage image = ImageIO.read(is);
// get all image writers for JPG format
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jp2k");
if (!writers.hasNext())
throw new IllegalStateException("No writers found");
ImageWriter writer = (ImageWriter) writers.next();
J2KImageWriter
J2KImageWriteParam jwp = (J2KImageWriteParam) writer.getDefaultWriteParam();
// J2KImageWriteParam jwp = new J2KImageWriteParam();
boolean lossless = true;
jwp.setLossless(lossless);
// jwp.setFilter(J2KImageWriteParam.FILTER_97);
if (!lossless) {
jwp.setEncodingRate(8.0 / 2);
}
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(os);
writer.setOutput(ios);
writer.write(null, new IIOImage(image, null, null), jwp);
ios.flush();
ios.close();
} catch (IOException e) {
e.printStackTrace();
}
我正在尝试使用上面的代码。
答案 0 :(得分:2)
答案 1 :(得分:0)
我首先尝试javax.ImageIO,因为您的系统可能有JPEG2000格式的提供商。
否则:http://www.deic.uab.cat/~francesc/显然是针对java。