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

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

Description

Crops the image to the given size starting at (0,0)

License

Open Source License

Parameter

Parameter Description
image The image to crop
width width in pixels
height height in pixels

Declaration

private static BufferedImage cropImage(BufferedImage image, int width, int height) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

public class Main {
    /**//  www .ja va2 s  .  c o  m
     * Crops the image to the given size starting at (0,0)
     * 
     * @param image
     *            The image to crop
     * @param width
     *            width in pixels
     * @param height
     *            height in pixels
     */
    private static BufferedImage cropImage(BufferedImage image, int width, int height) {
        if (image.getWidth() == width && image.getHeight() == height) {
            return image;
        }
        return image.getSubimage(0, 0, width, height);
    }
}

Related

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