I need to read a BufferedImage
from file, which doesn't use DataBufferInt
(as normally), but DataBufferFloat
.
Please note: I don't just need some standalone DataBufferFloat
, but really a BufferedImage
with underlying DataBufferFloat
.
The API around these things is very complex, I just can't find how to do this.
Please help.
EDIT
Found out what is not working:DataBufferDouble dbd = new DataBufferDouble(destWidth * destHeight * 4);
// Exception here:
// java.lang.IllegalArgumentException: Unsupported data type 5
WritableRaster wr = WritableRaster.createPackedRaster(
dbd, destWidth, destHeight, 32, new Point(0, 0));
BufferedImage bi = new BufferedImage(ColorModel.getRGBdefaul开发者_如何学JAVAt(),
wr, false, (Hashtable<?, ?>) null);
createPackedRaster
is not appropriate for this. It creates a Raster
with a SinglePixelPackedSampleModel
, which stores r/g/b/a values in bit fields within an int
, so its transferType
can only be an integral type.
You probably want a generic raster with a PixelInterleavedSampleModel
e.g.
DataBufferDouble dbd = new DataBufferDouble(destWidth * destHeight * 4);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_DOUBLE, destWidth, destHeight, 4, destWidth * 4, new int[] {2, 1, 0, 3});
WritableRaster wr = WritableRaster.createWritableRaster(sm, dbd, null);
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), true, true, ColorModel.TRANSLUCENT, DataBuffer.TYPE_FLOAT);
BufferedImage bi = new BufferedImage(cm, wr, true, new Hashtable<Object, Object>());
精彩评论