title: How to make an exact copy of image in java?
body: <p>After loading the image, I want to create an exact copy of the image whereby the quality and scale can remain the same. With my current code, the quality was reduced. </p>
  
  <pre><code>public class Image {
      private static final String path = "C:/Users.../src/7horses.jpg";
      private static final File file = new File(path);
  
      static BufferedImage deepCopy(BufferedImage bi) throws IOException {
          String saveAs = "copy.jpg";
          ColorModel cm = bi.getColorModel();
          boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
          WritableRaster raster = bi.copyData(null);
          BufferedImage cImg = new BufferedImage(cm, raster, isAlphaPremultiplied, null);
          File saveImage = new File("C:/Users.../src", saveAs);
          ImageIO.write(cImg, "jpg", saveImage);
          return cImg;
      }
  
      public static void main(String[] args) throws IOException {
          BufferedImage cp, img;
          img = ImageIO.read(file); 
          cp = deepCopy(img);
      }
  }
  </code></pre>