Here you can find the source of compression(BufferedImage src, int scale)
public static BufferedImage compression(BufferedImage src, int scale)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; public class Main { public static BufferedImage compression(BufferedImage src, int scale) { return compression(src, scale, scale); }/*from www . j a va 2s . c om*/ public static BufferedImage compression(BufferedImage src, int widthScale, int heightScale) { int oldWidth = src.getWidth(); int oldHeight = src.getHeight(); int width = oldWidth / widthScale + ((oldWidth % widthScale) > 0 ? 1 : 0); int height = oldHeight / heightScale + ((oldHeight % heightScale) > 0 ? 1 : 0); BufferedImage dest = new BufferedImage(width, height, src.getType()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int rgb = src.getRGB(x * widthScale, y * heightScale); dest.setRGB(x, y, rgb); } } return dest; } }