Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

java - How to achieve jpeg lossless?

How to achieve jpeg-lossess in Java?

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);

Will throw an exception:

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)

The param.getCompressionTypes() only print [JPEG].

using JAI(version 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");

Also throw exception:

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)

Can you write an sample please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Standard java does not have a compression type for JPEG-LS.

You can to download and use the JAI (Java Advanced Imaging) API though which I beleive includes such a compression type.

Can be downloaded from here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...