Will,
Here's a snippet I recently wrote to create "true-colour" composites
from 3 seperate byte channels. It first creates a byte[][] from the
data buffers of the 3 channels that go into the red, green and blue
"bands". You could replace this by the byte[] you have read from file.
In my case, I need to create a banded raster from the byte[][], make
that into a WriteableRaster, and with that, create the BufferImage (which
also req uires a colormodel).
Although this is only 6 lines, it works wonderfully nice. I guess it's maybe
not the best way, but it's quite wonderful code to demonstrate the
principle behind it. I was quite amazed that it was more or less bug free the
first time I wrote it (see my last comment).
I got most of my clues from javadoc and the O'Reilly Java 2D book (Jonathan
Knudsen).
// first create a color model
java.awt.color.ColorSpace cS =
java.awt.color.ColorSpace.getInstance(java.awt.color.ColorSpace.CS_sRGB);
ColorModel cM = new ComponentColorModel(cS, new int[] {8,8,8},
false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
// Now, stuff a data buffer with the individual byte channels
byte db[][] = {
((DataBufferByte)mImageR.getRaster().getDataBuffer()).getData(),
((DataBufferByte)mImageG.getRaster().getDataBuffer()).getData(),
((DataBufferByte)mImageB.getRaster().getDataBuffer()).getData() };
DataBufferByte rgb = new DataBufferByte(db, mImageR.getWidth() *
mImageR.getHeight() * 3);
// And store as a band interleafed raster
WritableRaster wR = WritableRaster.createBandedRaster(rgb, mImageR.getWidth(),
mImageR.getHeight(), mImageR.getWidth(), new int[] {0,1,2}, new int[]
{0,0,0}, null);
// Finally, create a BufferedImage out of this
mImage = new BufferedImage(cM, wR, false, null);
// Piece of cake! What a fantastic stuff this is!
GL
On Wednesday, June 07, 2000 5:14 PM, Bracken, Will [SMTP:[EMAIL PROTECTED]] wrote:
> I have images in .raw format. I need to read them into Image or
> BufferedImage format. Anyone have any sample code to do the I/O necessary to
> read in the byte[] and/or have code to construct the image via the byte[]?
> Thanks in advance,
> Will Bracken
>
> ===========================================================================
> 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".
===========================================================================
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".