posted 15 years ago
something like that, but it's wrong:SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
w, h,
new int[] {0xFF});
DataBuffer db = new DataBufferByte( bdata, w*h, 0);
Point p = new Point(0,0);
WritableRaster raster = Raster.createWritableRaster(sm, db, p);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
int[] nBits = {24};
ColorModel cm = new ComponentColorModel(cs, nBits, false, true,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
bufi =
new BufferedImage(cm, raster, false, null);
second version:
public BufferedImage getImagen(byte[] bdata)
{
final int colors = 32;
final int width = 200;
final int height = 200;
Image img;
// Create the color map
byte[] rbmap = new byte[colors];
byte[] gmap = new byte[colors];
for (int i = 0; i < colors; i++)
gmap[i] = (byte)((i * 255) / (colors - 1));
// Create the color model
int bits = (int)Math.ceil(Math.log(colors) /
Math.log(2));
IndexColorModel model = new IndexColorModel(bits,
colors,
rbmap, gmap, rbmap);
// Create the pixels
int pixels[] = new int[width * height];
int index = 0;
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
pixels[index++] = (x * colors) / width;
MemoryImageSource source = new MemoryImageSource(width, height,
model, pixels, 0, width);
// Create the image
Image = ? // i need some createImage
}
[ June 22, 2008: Message edited by: Bruno Danis ]