get Sub Image BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

get Sub Image BufferedImage

Demo Code


//package com.java2s;
import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage getSubImage(BufferedImage image, int subX,
            int subY, int subWidth, int subHeight) {
        BufferedImage sub = new BufferedImage(subWidth, subHeight,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g = sub.createGraphics();
        g.drawImage(image, -subX, -subY, null);
        g.dispose();//w  ww  . j  a v  a  2 s  . c o m

        return sub;
    }
}

Related Tutorials