Example usage for java.awt.image Raster createCompatibleWritableRaster

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

Introduction

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

Prototype

public WritableRaster createCompatibleWritableRaster(int w, int h) 

Source Link

Document

Create a compatible WritableRaster with the specified size, a new SampleModel, and a new initialized DataBuffer.

Usage

From source file:CheckAlignmentOpImage.java

public Raster computeTile(int x, int y) {
    Raster r1 = source1.getTile(x, y);
    Raster r2 = source2.getTile(x, y);

    int xBounds = r1.getWidth();
    if (r2.getWidth() < xBounds)
        xBounds = r2.getWidth();/* ww w .  ja v a2 s  . co  m*/
    int yBounds = r1.getHeight();
    if (r2.getHeight() < yBounds)
        yBounds = r2.getHeight();

    WritableRaster wr;
    wr = r1.createCompatibleWritableRaster(xBounds, yBounds);

    int tmpi;
    int tmpj;
    for (int i = 0; i < wr.getWidth(); i++)
        for (int j = 0; j < wr.getHeight(); j++) {
            tmpi = i / samplingPeriod;
            tmpj = j / samplingPeriod;
            if ((tmpi % 2 == 0) && (tmpj % 2 == 0))
                wr.setDataElements(i, j, r2.getDataElements(i, j, null));
            else if ((tmpi % 2 != 0) && (tmpj % 2 != 0))
                wr.setDataElements(i, j, r2.getDataElements(i, j, null));
            else
                wr.setDataElements(i, j, r1.getDataElements(i, j, null));
        }
    return wr;
}