1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
private static void switchPic(String source, String target) throws IOException {
if (Files.exists(Paths.get(target))) { Files.delete(Paths.get(target)); }
BufferedImage read = ImageIO.read(new File(source)); JPEGImageWriter w = new JPEGImageWriter(new JPEGImageWriterSpi()); w.setOutput(new FileImageOutputStream(new File(target))); ImageWriteParam p = w.getDefaultWriteParam(); p.setProgressiveMode(ImageWriteParam.MODE_COPY_FROM_METADATA); p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); p.setCompressionQuality(0.7F); w.write(null, new IIOImage(read, null, null), p); }
|