Java BufferedImage Subimage getSubImage(BufferedImage img, int x, int y, int w, int h)

Here you can find the source of getSubImage(BufferedImage img, int x, int y, int w, int h)

Description

For some reason, BufferedImage.getSubimage returns something which is incompatible with JAI.

License

Educational Community License

Declaration

public static BufferedImage getSubImage(BufferedImage img, int x, int y, int w, int h) 

Method Source Code

//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;
    }
}

Related

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