Java BufferedImage Subimage getSubImage(BufferedImage srcImage, int x, int y, int factorWidth, int factorHeight)

Here you can find the source of getSubImage(BufferedImage srcImage, int x, int y, int factorWidth, int factorHeight)

Description

Gets the sub image from original image by specified X,Y coords and Width and Height.

License

LGPL

Parameter

Parameter Description
srcImage the image to get sub image from
x the X coordinate of the upper-left corner of the specified rectangular region
y the Y coordinate of the upper-left corner of the specified rectangular region
factorWidth the width of the specified rectangular region
factorHeight the height of the specified rectangular region

Return

sub-image from original image

Declaration

public static BufferedImage getSubImage(BufferedImage srcImage, int x, int y, int factorWidth,
        int factorHeight) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.image.BufferedImage;

public class Main {
    /**//from  ww  w.j  a  va  2  s . c o  m
     * Gets the sub image from original image by specified X,Y coords and Width and Height.
     *
     * @param srcImage
     *            the image to get sub image from
     * @param x
     *            the X coordinate of the upper-left corner of the specified rectangular region
     * @param y
     *            the Y coordinate of the upper-left corner of the specified rectangular region
     * @param factorWidth
     *            the width of the specified rectangular region
     * @param factorHeight
     *            the height of the specified rectangular region
     * @return sub-image from original image
     */
    public static BufferedImage getSubImage(BufferedImage srcImage, int x, int y, int factorWidth,
            int factorHeight) {
        if (factorWidth < srcImage.getWidth() && factorHeight < srcImage.getHeight()) {
            return srcImage.getSubimage(x, y, factorWidth, factorHeight);
        }
        return srcImage;
    }
}

Related

  1. getSubImage(BufferedImage image, int x, int y, int width, int height)
  2. getSubimage(BufferedImage image, int x, int y, int width, int height)
  3. getSubimage(BufferedImage image, int x, int y, int width, int height)
  4. getSubImage(BufferedImage img, int x, int y, int w, int h)
  5. getSubImage(BufferedImage img, Rectangle area)