Java Utililty Methods BufferedImage Compress

List of utility methods to do BufferedImage Compress

Description

The list of methods to do BufferedImage Compress are organized into topic(s).

Method

BufferedImagecompress(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);
voidcompress(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);
...
BufferedImagecompressImage(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;
BufferedImagecompression(BufferedImage src, int scale)
compression
return compression(src, scale, scale);
ImagecompressPhoto(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;