Here you can find the source of cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)
public static BufferedImage cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics; import java.awt.image.BufferedImage; public class Main { public static BufferedImage cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor) { int lc = (int) (leftCropFactor * image.getWidth()); int rc = (int) (rightCropFactor * image.getWidth()); int tc = (int) (topCropFactor * image.getHeight()); int bc = (int) (bottomCropFactor * image.getHeight()); BufferedImage dest = new BufferedImage(image.getWidth() - (lc + rc), image.getHeight() - (tc + bc), BufferedImage.TYPE_BYTE_GRAY); Graphics g = dest.getGraphics(); g.drawImage(image, 0, 0, image.getWidth() - (lc + rc), image.getHeight() - (tc + bc), lc, tc, image.getWidth() - rc, image.getHeight() - bc, null); g.dispose();/* www .j a v a2 s. co m*/ return dest; } }