[英]Java ImageIO: How can I read a BufferedImage from file, so that it uses DataBufferFloat?
I need to read a BufferedImage
from file, which doesn't use DataBufferInt
(as normally), but DataBufferFloat
. 我需要从文件中读取
BufferedImage
,该文件不使用DataBufferInt
(通常),而是使用DataBufferFloat
。
Please note: I don't just need some standalone DataBufferFloat
, but really a BufferedImage
with underlying DataBufferFloat
. 请注意:我不仅需要一些独立的
DataBufferFloat
,而且实际上需要一个具有基础DataBufferFloat
的BufferedImage
。
The API around these things is very complex, I just can't find how to do this. 围绕这些事情的API非常复杂,我只是找不到如何执行此操作。
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.getRGBdefault(),
wr, false, (Hashtable<?, ?>) null);
createPackedRaster
is not appropriate for this. createPackedRaster
不适合此操作。 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. 它使用
SinglePixelPackedSampleModel
创建一个Raster
,该Raster
将r / g / b / a值存储在int
位字段中,因此其transferType
只能是整数类型。
You probably want a generic raster with a PixelInterleavedSampleModel
eg 您可能想要具有
PixelInterleavedSampleModel
的通用栅格,例如
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>());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.