Example usage for java.awt.image Raster getDataBuffer

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

Introduction

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

Prototype

public DataBuffer getDataBuffer() 

Source Link

Document

Returns the DataBuffer associated with this Raster.

Usage

From source file:org.photovault.swingui.ImageTile.java

/**
 * Draws the tile if it is found in cache. Otherwise, schedule a request
 * for computing it./* w ww. j  a va 2s . c  om*/
 * @param cache
 * @param g
 */
public void drawTile(TileCache cache, Graphics2D g) {
    Raster r = cache.getTile(img, tileX, tileY);
    if (r == null) {
        if (tileReq == null) {
            Point[] tileCoord = new Point[1];
            tileCoord[0] = new Point(tileX, tileY);
            tileReq = img.queueTiles(tileCoord);
        }
    } else {
        DataBuffer buf = r.getDataBuffer();
        SampleModel sm = r.getSampleModel();
        WritableRaster wr = Raster.createWritableRaster(sm, buf, new Point(0, 0));
        ColorModel cm = img.getColorModel();
        BufferedImage bufImg = new BufferedImage(cm, wr, false, null);
        g.drawImage(bufImg, null, tileX * tileWidth, tileY * tileHeight);
    }
}