Example usage for java.awt.image Raster getBounds

List of usage examples for java.awt.image Raster getBounds

Introduction

In this page you can find the example usage for java.awt.image Raster getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Returns the bounding Rectangle of this Raster.

Usage

From source file:GraphicsUtil.java

public static void copyBand(Raster src, int srcBand, WritableRaster dst, int dstBand) {

    Rectangle sR = src.getBounds();
    Rectangle dR = dst.getBounds();
    Rectangle cpR = sR.intersection(dR);

    copyBand(src, cpR, srcBand, dst, cpR, dstBand);
}

From source file:GraphicsUtil.java

public static void copyBand(Raster src, Rectangle sR, int sBand, WritableRaster dst, Rectangle dR, int dBand) {
    int dy = dR.y - sR.y;
    int dx = dR.x - sR.x;
    sR = sR.intersection(src.getBounds());
    dR = dR.intersection(dst.getBounds());
    int width, height;
    if (dR.width < sR.width)
        width = dR.width;// www.  ja v a 2 s .c  o  m
    else
        width = sR.width;
    if (dR.height < sR.height)
        height = dR.height;
    else
        height = sR.height;

    int x = sR.x + dx;
    int[] samples = null;
    for (int y = sR.y; y < sR.y + height; y++) {
        samples = src.getSamples(sR.x, y, width, 1, sBand, samples);
        dst.setSamples(x, y + dy, width, 1, dBand, samples);
    }
}