Java BufferedImage Operation newSubimage(BufferedImage src, int x, int y, int w, int h)

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

Description

Returns an independent subimage of the given main image.

License

LGPL

Parameter

Parameter Description
src the source image.
x the x coordinate
y the y coordinate
w the width
h the height

Return

the extracted sub-image

Declaration

public static BufferedImage newSubimage(BufferedImage src, int x, int y, int w, int h) 

Method Source Code


//package com.java2s;
/*//from ww  w .  j  av a 2  s.  c  o m
 * Copyright 2008-2014, David Karnok 
 * The file is part of the Open Imperium Galactica project.
 * 
 * The code should be distributed under the LGPL license.
 * See http://www.gnu.org/licenses/lgpl.html for details.
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Returns an independent subimage of the given main image. copying data from the original image.
     * @param src the source image.
     * @param x the x coordinate
     * @param y the y coordinate
     * @param w the width
     * @param h the height
     * @return the extracted sub-image
     */
    public static BufferedImage newSubimage(BufferedImage src, int x, int y, int w, int h) {
        BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        int[] tmp = new int[w * h];
        src.getRGB(x, y, w, h, tmp, 0, w);
        bimg.setRGB(0, 0, w, h, tmp, 0, w);
        return bimg;
    }
}

Related

  1. markImageBorders(final BufferedImage img, final int startW, final int startH)
  2. matBytesToBufferedImage(byte[] data, int cols, int rows, int type)
  3. matte(BufferedImage image, int top, int bottom, int left, int right, Color bg)
  4. mirror(final BufferedImage image, final boolean horizontal)
  5. newOptimizedImageLike(GraphicsConfiguration destination, BufferedImage img)
  6. nNeighbors(BufferedImage image, int i, int j)
  7. nrChannels(BufferedImage img)
  8. numPixelsDifferent(BufferedImage imgA, BufferedImage imgB)
  9. offset(final BufferedImage image, final float[] scales, final float[] offsets)