Here you can find the source of cropImage(URL url, float x, float y, float w, float h, OutputStream out)
public static void cropImage(URL url, float x, float y, float w, float h, OutputStream out) throws IOException
//package com.java2s; /*// w w w. j av a2 s .c o m * Copyright (C) ${year} Omry Yadan <${email}> * All rights reserved. * * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information */ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.*; import java.net.*; public class Main { public static void cropImage(URL url, float x, float y, float w, float h, OutputStream out) throws IOException { InputStream in = url.openStream(); try { cropImage(in, x, y, w, h, out); } finally { in.close(); } } public static void cropImage(String imageName, float x, float y, float w, float h, OutputStream out) throws IOException { FileInputStream fin = new FileInputStream(imageName); try { cropImage(fin, x, y, w, h, out); } finally { fin.close(); } } public static void cropImage(InputStream in, float x, float y, float w, float h, OutputStream out) throws IOException { if (x < 0) x = 0; if (y < 0) y = 0; if (x + w > 100) w = 100 - x; if (y + h > 100) h = 100 - y; BufferedImage bi = ImageIO.read(in); int width = bi.getWidth(); int height = bi.getHeight(); BufferedImage cropped = bi.getSubimage((int) (width * x / 100), (int) (height * y / 100), (int) (width * w / 100), (int) (height * h / 100)); ImageIO.write(cropped, "jpeg", out); } }