List of utility methods to do BufferedImage Compress
BufferedImage | compress(BufferedImage image, float quality) compress try { ByteArrayOutputStream out = new ByteArrayOutputStream(); write(image, quality, out); return ImageIO.read(new ByteArrayInputStream(out.toByteArray())); } catch (IOException e) { throw new RuntimeException(e); |
void | compress(BufferedImage image, String path) compress ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam(); if (jpgWriteParam.canWriteCompressed()) { jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpgWriteParam.setCompressionQuality(0.5f); if (jpgWriteParam.canWriteProgressive()) { jpgWriteParam.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA); ... |
BufferedImage | compressImage(BufferedImage originalImage, int type, int width, int height) compress Image BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, width, height, null); g.dispose(); return resizedImage; |
BufferedImage | compression(BufferedImage src, int scale) compression return compression(src, scale, scale);
|
Image | compressPhoto(Image originImg, int newWidth, int newHeight) compress Photo Image newImg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); newImg.getGraphics().drawImage(originImg.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); return newImg; |