Here you can find the source of getSubImage(BufferedImage img, int x, int y, int w, int h)
public static BufferedImage getSubImage(BufferedImage img, int x, int y, int w, int h)
//package com.java2s; /*/*from w w w .jav a2 s . com*/ * Copyright 2013 Saint Louis University. Licensed under the * Educational Community 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.osedu.org/licenses/ECL-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.Graphics; import java.awt.image.BufferedImage; public class Main { /** * For some reason, BufferedImage.getSubimage returns something which is incompatible with * JAI. This is a hack to work around that problem. */ public static BufferedImage getSubImage(BufferedImage img, int x, int y, int w, int h) { BufferedImage result = new BufferedImage(w, h, img.getType()); Graphics g = result.getGraphics(); g.drawImage(img, 0, 0, w, h, x, y, w, h, null); g.dispose(); return result; } }