Here you can find the source of cropImage(BufferedImage image, int width, int height)
Parameter | Description |
---|---|
image | - the image to crop. |
width | - the width we want to crop to. |
height | - the height we want to crop to. |
public static BufferedImage cropImage(BufferedImage image, int width, int height)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics; import java.awt.image.BufferedImage; public class Main { /**/*from ww w . jav a 2 s .co m*/ * Crops an image to a specified size. * * @param image - the image to crop. * @param width - the width we want to crop to. * @param height - the height we want to crop to. * @return the cropped image. */ public static BufferedImage cropImage(BufferedImage image, int width, int height) { if (width > 0 && height > 0) { BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = result.getGraphics(); g.drawImage(image, 0, 0, width, height, null); g.dispose(); // Retuned the new scaled and cropped image. return result; } return image; } }