title: How to save lossless jpg in java?
body: <p>I have to save a jpeg image lossless. I am work on a steganography project but Java compressing and saving my result. I research every forums and try everything but it didn't work.</p>
  
  <p>Here my example code for lossless save a jpeg image:</p>
  
  <pre><code>BufferedImage image = ImageIO.read(new File("sources/image.jpg"));
  
  ImageWriter writer = ImageIO.getImageWritersByFormatName("JPEG").next();
  JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
  
  jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  jpegParams.setCompressionQuality(1f);
  
  writer.setOutput(ImageIO.createImageOutputStream(new File("example.jpg")));
  writer.write(null, new IIOImage(image,null,null), jpegParams);
  writer.dispose();
  </code></pre>
  
  <p>After this process I compute PSNR value is 28.53173 and "<em>example.jpg</em>"'s size is bigger than "<em>image.jpg</em>".</p>
  
  <p>I try import JAI library but I am not sure Java 8 is support JAI.</p>