> a small problem turns out to be a big problem for me: I want to
> display a two-dimensional short array (values <= 255) as a gray value
> image.
> Where can I find help for DataBuffer, ColorModel, Raster etc.
at the source
> and some example code? here it is:
at first you should create ColorMdel:
byte[] r = new byte[256];
for (int i = 0; i < r.length; i++) {
r[i] = (byte) i;
}
ColorModel icm = new IndexColorModel(8, 256, r, r, r);
there many ways to create (Buffered)Image:
first way:
^^^^^^
Before you can use DataBuffer you should copy all data to one array.
then create DataBufferByte:
DataBuffer buffer = new DataBufferByte(dataArray, dataArray.length, 0);
create Raster:
WritableRaster wr = Raster.createBandedRaster(buffer, width, height, width,
new int[] {0}, new int [] {0}, new Point(0,0));
create BufferedImage:
BufferedImage bi = new BufferedImage(icm, wr, false, new Hashtable());
second way (better):
^^^^^^^^^
create BufferedImage:
BufferedImage bi = new BufferedImage(width, height, TYPE_BYTE_INDEXED, icm);
I assume that your data is in 2D byte array:
byte [][] data = new byte[height][width];
then create int array to hold temporary data:
int [] buf = new int[width];
transfer your data into BufferedImage:
for(int i = 0; i < height; i++) {
//create ABGR pixel array
for(int j = 0; j < width; j++) {
int a = data[i][j] & 0xFF;
buf[j] = (0xFF << 24) | (a << 16) | (a << 8) || a;
}
//set pixels
bi.setRGB(0, j, width, 1, buf, 0, width);
}
> Thanks in advance.
you are welcome

Signature
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Lothar Leidner - 29 Nov 2004 21:15 GMT
Thank you again for your help, it worked.
Lothar