在java中使用DataBuffer.TYPE_FLOAT或DataBuffer.TYPE_DOUBLE写出BMP文件
我在使用 java 中的图像类时遇到问题。
我正在使用 DataBuffer.TYPE_DOUBLE 创建缓冲图像。这一切在记忆中都运行良好(我认为)。但当我尝试使用 ImageIO.write 编写它时,问题就开始了。
最初我没有遇到任何异常,而只是得到一个空的输出文件来解决我的麻烦。
在代码中进行了一番研究后,我发现 bmp 编写器不支持写入 type_double 类型的文件。
From: BMPImageWriterSpi.canEncodeImage:
if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
return false;
所以我的问题是,有人有办法将此类图像写入磁盘吗?任何文档或教程或链接都会有帮助。
谢谢, 巴兹尔·杜苏扎
I had a problem working with the image classes in java.
I am creating a buffered image with DataBuffer.TYPE_DOUBLE. This all works fine in memory (I think). But the problem starts when I try to write it using ImageIO.write.
Initially I was getting no exception at all and instead was only getting an empty output file for my troubles..
After a bit of poking around in the code, i found out that the bmp writer doesnt support writing type_double type of files.
From: BMPImageWriterSpi.canEncodeImage:
if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
return false;
So my question is, does anyone have a way of writing out those kind of images to disk? any documentation or tutorial, or link would be helpful.
Thanks,
Basil Dsouza
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 BMP 格式不使用任何浮点表示形式,因此从较高的层次来看,使用浮点数据来表示要写入为 BMP 的图像不太有意义。你真的需要这样做吗?为什么不是整数?
DataBuffer 的 javadoc。 TYPE_DOUBLE
表明它当前不适合使用。Since the BMP format doesn't use any floating-point representations, at a high level it doesn't quite make sense to use floating-point data to represent an image that you will write as a BMP. Do you really need to do that? Why not ints?
The javadoc for
DataBuffer.TYPE_DOUBLE
suggests it's not currently intended for use.