Java BufferedImage Subimage getSubImage(BufferedImage img, Rectangle area)

Here you can find the source of getSubImage(BufferedImage img, Rectangle area)

Description

get Sub Image

License

Open Source License

Declaration

public static BufferedImage getSubImage(BufferedImage img, Rectangle area) 

Method Source Code

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

import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage getSubImage(BufferedImage img, Rectangle area) {
        BufferedImage newImg = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_ARGB);
        int i = 0;
        int j = 0;
        int x2 = area.x + area.width;
        int y2 = area.y + area.height;

        for (int x = area.x; x < x2; ++x) {
            for (int y = area.y; y < y2; ++y) {
                newImg.setRGB(i, j++, img.getRGB(x, y));
            }/*from  w w  w  .j a  v  a  2 s.  c  o  m*/

            ++i;
            j = 0;
        }

        return newImg;
    }
}

Related

  1. getSubimage(BufferedImage image, int x, int y, int w, int h)
  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 image, int x, int y, int width, int height)
  5. getSubImage(BufferedImage img, int x, int y, int w, int h)
  6. getSubImage(BufferedImage srcImage, int x, int y, int factorWidth, int factorHeight)