Java BufferedImage Crop cropImage(BufferedImage image, int x, int y, int width, int height)

Here you can find the source of cropImage(BufferedImage image, int x, int y, int width, int height)

Description

Crop image

License

Open Source License

Parameter

Parameter Description
image The image
x x-cooordinate of the image origin
y y-cooordinate of the image origin
width The width to crop to
height The height to crop to

Return

the cropped image

Declaration

static public BufferedImage cropImage(BufferedImage image, int x, int y, int width, int height) 

Method Source Code

//package com.java2s;
/**// w ww.  ja  va2s . c  om
 * * $Id: ImageUtils.java 22 2005-06-14 05:17:45Z rej $
 * Copyright (c) 2002 Sun Microsystems, Inc.
 * *
 * * See the file "license.terms" for information on usage and redistribution
 * * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 **/

import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**
     * Crop image
     * @param image The image
     * @param x x-cooordinate of the image origin
     * @param y y-cooordinate of the image origin
     * @param width The width to crop to
     * @param height The height to crop to
     * @return the cropped image
     */
    static public BufferedImage cropImage(BufferedImage image, int x, int y, int width, int height) {
        BufferedImage cropped = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        Graphics g = cropped.getGraphics();
        g.drawImage(image, x, y, null);

        return cropped;
    }
}

Related

  1. cropImage(BufferedImage image, int cropWidth, int cropHeight)
  2. cropImage(BufferedImage image, int fromX, int fromY, int width, int height)
  3. cropImage(BufferedImage image, int lc, int rc, int tc, int bc)
  4. cropImage(BufferedImage image, int width, int height)
  5. cropImage(BufferedImage image, int width, int height)
  6. cropImage(BufferedImage image, int x1, int y1, int x2, int y2)
  7. cropImage(BufferedImage src, int x, int y, int w, int h)
  8. cropImage(BufferedImage src, int x, int y, int w, int h)
  9. cropImage(final BufferedImage img, int x, int y, int w, int h, double xScale, double yScale)