Hi

I think the basic problem is that createChild() is designed to create a
sub-raster that is *spatially* a child of the parent one, but shares the
same databuffer and sample model. In your case, you want the child rasters
to be spatially congruent to the parent (i.e., same origin and size), but to
use slightly different sample models to reflect the fact that the data for
the i'th raster starts at offset i*width in the databuffer. Given this, you
probably want to use the constructor to create the child rasters:

Point origin = new Point(0,0);
...
wi = new WritableRaster(sampleModel_i, wr.getDatabuffer(), origin)

where sampleModel_i is something like

int[] offsets = new int[] {i*w};
sampleModel_i = new ComponentSampleModel(DataBuffer.TYPE_USHORT, w, h, 1,
w*n, offsets);

This assumes that each pixel has a single band. I wasn't sure from your
message what type of sample model you were actually expecting. If the
underlying sample model is, say, pixel packed, you might have more problems,
because I can't see with those sample models how to provide an offset into
the data buffer for the first sample. Unfortunately my train for JavaOne
leaves in a minute, so I can't dig any deeper, but I'll take another look
tonight unless someone else has come up with the answer in the mean time.
Good luck!

Cheers,
Pete

--
Pete Cockerell
California, USA
http://216.102.89.91

----- Original Message -----
From: Denis Riedijk <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 17, 1999 6:06 AM
Subject: BufferedImage and WriteableRaster problems


> Hi all, I have got a question:
> In my project I need to display data from a reconstruction in the form of
some
> images. The data is in a big array (Unsigned Shorts)
>
> I thought that I could just create a big Raster containing all of the data
(a
> N*(M*N) image), where N is the size of an individual image, and M is the
number
> of images. And than create subimages by calling
> .createChild(0,index*N,N,N,0,0,null) to get the image numbered index.
>
> Here is a piece of the code :
> WriteableRaster wr,w1,w2,w3,w4;
> wr=Raster.createInterleavedRaster(short_db,w,4*h,w,1,bandOffsets,null);
>
w1=(wr.createChild(0,0,w,h,0,0,null)).createWritableRaster(wr.getSampleModel
(),null);
>
w2=(wr.createChild(0,0,w,h,0,0,null)).createWritableRaster(wr.getSampleModel
(),null);
>
w3=(wr.createChild(0,0,w,h,0,0,null)).createWritableRaster(wr.getSampleModel
(),null);
>
w4=(wr.createChild(0,0,w,h,0,0,null)).createWritableRaster(wr.getSampleModel
(),null);
>
> ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_GRAY);
> int[] bits={16};
> ComponentColorModel cm=new
ComponentColorModel(cs,bits,false,false,Transparency.OPAQUE,DataBuffer.TYPE_
USHORT);
> BufferedImage one=new BufferedImage(cm,w1,cm.isAlphaPremultiplied(),null);
> BufferedImage two=new BufferedImage(cm,w2,cm.isAlphaPremultiplied(),null);
> BufferedImage three=new
BufferedImage(cm,w3,cm.isAlphaPremultiplied(),null);
> BufferedImage four=new
BufferedImage(cm,w4,cm.isAlphaPremultiplied(),null);
>
>
> But now all four images are just black..
> Does anybody know what I am doing wrong ???
>

Reply via email to