Hi,
I have another question regarding the creation of a buffered
image. I used ur idea for a gray scale image and it worked fine.
Now I have a colored image, not a gray scale image. I want to
create a bufferedImage frm the data. I did not really understand
what a "band" and "bank" refers to described in the API for
creating a raster.
Here I am attaching a sample piece of code....
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
cm = new ComponentColorModel(cs, new int[]{8, 8, 8}, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
int[] band = new int[]{0};
db = new DataBufferByte(readSlice(i, slicesize), texturewidth *
textureheight * 3); // readSlice method reads an RGB image into a
byte array and returns it
raster = WritableRaster.createInterleavedRaster(db, texturewidth,
textureheight, texturewidth * 3, 3, band, null);
img = new BufferedImage(cm, raster, true, null);
Following is the exception I am getting...
Exception in thread "main" java.lang.IllegalArgumentException:
Raster ByteInterleavedRaster: width = 128 height = 128
#numDataElements 1 dataOff[0] = 0 is incompatible with ColorModel
ColorModel: #pixelBits = 24 numComponents = 3 color space =
java.awt.color.ICC_ColorSpace@5fafd1 transparency = 1 has alpha =
false isAlphaPre = false
at
java.awt.image.BufferedImage.<init>(BufferedImage.java:517)
at Scene3DCube.create3DTexture(Scene3DCube.java:215)
at Scene3DCube.createSceneGraph(Scene3DCube.java:113)
at Scene3DCube.<init>(Scene3DCube.java:95)
at Scene3DCube.main(Scene3DCube.java:472)
Could u please give me some suggestions...
Thanks,
pujita
On Fri, 01 Mar 2002 Markus Bengtsson wrote :
>Hi there
>Do this
>
>tmp2 = new byte[128];
>DataBuffer db = new DataBufferByte(tmp2,tmp2.length);
>WritableRaster raster =
>WritableRaster.createInterleavedRaster(db,width,height,width,1,new
>int[]{0},null);
>ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
>ComponentColorModel cm = new ComponentColorModel(cs,new
>int[]{8},false,false,Transparency.OPAQUE,DataBuffer.TYPE_BYTE);
>BufferedImage img = new BufferedImage(cm, raster,true,null);
>
>This will create an grayscale image
>/Markus
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".