Example usage for java.awt.image Raster createBandedRaster

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

Introduction

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

Prototype

public static WritableRaster createBandedRaster(DataBuffer dataBuffer, int w, int h, int scanlineStride,
        int[] bankIndices, int[] bandOffsets, Point location) 

Source Link

Document

Creates a Raster based on a BandedSampleModel with the specified DataBuffer, width, height, scanline stride, bank indices, and band offsets.

Usage

From source file:TestImage2.java

public static RenderedImage toRenderedImage(String[] rows) {
    // Create the DataBuffer to hold the pixel samples
    final int width = rows[0].length();
    final int height = rows.length;
    final int size = width * height;
    byte[] pixels = new byte[size];
    int index = 0;
    for (String row : rows) {
        for (int x = 0; x < width; x++) {
            pixels[index++] = (byte) decodeGray(row.charAt(x));
        }//from  ww  w . ja v  a 2s.c o  m
    }
    DataBuffer dataBuffer = new DataBufferByte(pixels, size);

    // Create Raster
    WritableRaster writableRaster = Raster.createBandedRaster(dataBuffer, width, height, width, // scanlineStride
            new int[] { 0 }, // bankIndices,
            new int[] { 0 }, // bandOffsets,
            null); // location

    // Create the image
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    bufferedImage.setData(writableRaster);

    return bufferedImage;
}