Okay I am a bit frustrated by now !
I found a way to solve that problem.
Sun engineers have nicely abstracted all properties of a graphics surface.
The key class is WritableRaster which uses a DataBuffer. A DataBuffer is an encapsulation of the actual data representation. For example the most used implementation of DataBuffer is the DataBufferByte which is implemented by a byte array. So the way to go is implement an own version of Data Buffer:
[quote]public class DataBufferDirectByte extends DataBuffer {
protected ByteBuffer directByteBuffer;
public DataBufferDirectByte(ByteBuffer directByteBuffer) {
super(TYPE_BYTE, directByteBuffer.capacity());
this.directByteBuffer = directByteBuffer;
}
public int getElem(int bank, int i) {
return directByteBuffer.get(i);
}
public void setElem(int bank, int i, int val) {
directByteBuffer.put(i, (byte)val);
}
public ByteBuffer getDirectByteBuffer() {
return directByteBuffer;
}
}
[/quote]
Very Easy uh ? 
Afterwards one has to wade through lots of other classes, there need to be surfaceformats and colormodels defined before it is finally possible to build an ImageBuffer.
This looks like this:
[quote]int[] offsetarray = {0,1,2,3};
PixelInterleavedSampleModel smodel =
new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 256,256,4,2564,offsetarray);
WritableRaster r = (WritableRaster) Raster.createRaster(smodel,
new DataBufferDirectByte(BufferUtils.allocateDirectByteBuffer(2564)), new Point(0,0));
ColorModel m = ImageUtil.createColorModel(r.getSampleModel());
BufferedImage i = new BufferedImage(m,r,false, null
);
[/quote]
The BufferUtils class was written by me.
But then happens the big #!$5$!*
A class somewhere inside the jdk jungle complains that our newly introduced DataBuffer is not of byte type. What the *!& ? We have defined it to be of byte type by calling the constructor of the superclass with the apropriate parameter;
super(TYPE_BYTE, directByteBuffer.capacity());
The type might be queried then with the DataBuffer.getDataType method.
Then I have a look at the implementation of this “ByteComponentRasters” class and what do i find ???
if (!(dataBuffer instanceof DataBufferByte)) {
throw new RasterFormatException(
"ByteComponentRasters must have "
+ "byte DataBuffers");
}
That makes me wanna cry ! They actually confused their design ! They are checking the actual class types, instead they should
have been using:
switch(dataBuffer.getDataType);
Oh nooo! I actually think that this is a bug and was not meant this way. No point in abstracting everything, so the system may nicely be extended, and then to allow only one type.
>:( >:( >:(
No more motivation to continue…
What do you think about this ?