Skip to main content

Cannot able to Byte Array Colored Image into JPEG

3 replies [Last post]
Anonymous

Hi,

I am not able to convert a byte array colored image to JPGE or PNG, Please help me out...

The details are as follows.

byteImageArray[] is a byte[] which i have got from Dicom file.

Created the dataBank as ....
dataBank = new DataBufferByte(byteImageArray [],width * height);

Then created the BandedSampleModel as...
BandedSampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE,width,height,1);

Then wrote the code for WriteableRaster...
Point origin = new Point();
WritableRaster raster = Raster.createWritableRaster(sampleModel,dataBank,origin);

Then created the ColorSpace and the Color Model respectiviely...
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);

Then created the TiledImage...
TiledImage tiledImage = new TiledImage(0,0,width,height,0,0,sampleModel,colorModel);

This is the line i am getting most of the time exception::: a) ColorModel is not compatible with the Sample Model.

Please let me know if someone has tried this out.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Aastha Bhardwaj

Hi,

The Javadoc for the specific ColorModel subclasses mentions which
specific SampleModels are compatible with them, so you could take a look
at the Javadoc for the ColorModel you are using. It might be that
BandedSampleModel is not compatible with the ColorModel you are using.
Unless your data is structured in a band interleaved fashion (as opposed
to pixel interleaved), PixelInterleavedSampleModel is a more common
choice for the SampleModel to use.

If that does not help, please provide a self-contained compiling test
case that we can use to reproduce the problem.

Aastha

---------------------
Aastha Bhardwaj
Java Advanced Imaging
Sun Microsystems

>
> I am not able to convert a byte array colored image to JPGE or PNG, Please help me out...
>
> The details are as follows.
>
> byteImageArray[] is a byte[] which i have got from Dicom file.
>
> Created the dataBank as ....
> dataBank = new DataBufferByte(byteImageArray [],width * height);
>
> Then created the BandedSampleModel as...
> BandedSampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE,width,height,1);
>
> Then wrote the code for WriteableRaster...
> Point origin = new Point();
> WritableRaster raster = Raster.createWritableRaster(sampleModel,dataBank,origin);
>
> Then created the ColorSpace and the Color Model respectiviely...
> ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
>
> Then created the TiledImage...
> TiledImage tiledImage = new TiledImage(0,0,width,height,0,0,sampleModel,colorModel);
>
> This is the line i am getting most of the time exception::: a) ColorModel is not compatible with the Sample Model.
>
> Please let me know if someone has tried this out.
> ---
> [Message sent by forum member 'SantoshB' (Santosh Bhushan)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=81237&#81237
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

bpb
Offline
Joined: 2004-06-23
Points: 0

Whence the value of 'colorModel'?

Brian

> Hi,
>
> I am not able to convert a byte array colored image
> to JPGE or PNG, Please help me out...
>
> The details are as follows.
>
> byteImageArray[] is a byte[] which i have got from
> Dicom file.
>
> Created the dataBank as ....
> dataBank = new DataBufferByte(byteImageArray [],width
> * height);
>
> Then created the BandedSampleModel as...
> BandedSampleModel sampleModel = new
> w
> BandedSampleModel(DataBuffer.TYPE_BYTE,width,height,1)
> ;
>
> Then wrote the code for WriteableRaster...
> Point origin = new Point();
> WritableRaster raster =
> ster =
> Raster.createWritableRaster(sampleModel,dataBank,origi
> n);
>
> Then created the ColorSpace and the Color Model
> respectiviely...
> ColorSpace colorSpace =
> ColorSpace.getInstance(ColorSpace.CS_sRGB);
>
> Then created the TiledImage...
> TiledImage tiledImage = new
> TiledImage(0,0,width,height,0,0,sampleModel,colorModel
> );
>
> This is the line i am getting most of the time
> exception::: a) ColorModel is not compatible with the
> Sample Model.
>
> Please let me know if someone has tried this out.

Anonymous

Regards,
Santosh