Java BufferedImage Crop cropImage(BufferedImage image, int x1, int y1, int x2, int y2)

Here you can find the source of cropImage(BufferedImage image, int x1, int y1, int x2, int y2)

Description

Crops (returns subimage) of specified input image at specified points.

License

Apache License

Parameter

Parameter Description
image image to crop
x1 top left x coordinate
y1 top left y coordinate
x2 bottom right x coordinate
y2 bottom right y coordinate

Return

image croped at specified points

Declaration

public static BufferedImage cropImage(BufferedImage image, int x1, int y1, int x2, int y2) 

Method Source Code

//package com.java2s;
/**//from w  w w  . ja va  2s . c o m
 * Copyright 2010 Neuroph Project http://neuroph.sourceforge.net
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Crops (returns subimage) of specified input image at specified points.
     *
     * @param image image to crop
     * @param x1 top left x coordinate
     * @param y1 top left y coordinate
     * @param x2 bottom right x coordinate
     * @param y2 bottom right y coordinate
     *
     * @return image croped at specified points
     */
    public static BufferedImage cropImage(BufferedImage image, int x1, int y1, int x2, int y2) {
        return image.getSubimage(x1, y1, x2 - x1, y2 - y1);
    }
}

Related

  1. cropImage(BufferedImage image, int fromX, int fromY, int width, int height)
  2. cropImage(BufferedImage image, int lc, int rc, int tc, int bc)
  3. cropImage(BufferedImage image, int width, int height)
  4. cropImage(BufferedImage image, int width, int height)
  5. cropImage(BufferedImage image, int x, int y, int width, int height)
  6. cropImage(BufferedImage src, int x, int y, int w, int h)
  7. cropImage(BufferedImage src, int x, int y, int w, int h)
  8. cropImage(final BufferedImage img, int x, int y, int w, int h, double xScale, double yScale)
  9. cropImageRelative(BufferedImage image, double leftCropFactor, double rightCropFactor, double topCropFactor, double bottomCropFactor)