我尝试(在 BufferedImage
中)读取 1 或 3 个 channel 的 14 或 16 位图像(灰度或 RGB)。准确地说,该图像的每个颜色分量都存储在 14 或 16 位上。
我的代码(使用 Apache Sanselan/Imaging)读取图像,但每个颜色分量被截断为 8 位。
File f = new File("/tmp/a.tiff");
Map<String, ManagedImageBufferedImageFactory> params =
new HashMap<String, ManagedImageBufferedImageFactory>();
params.put(ImagingConstants.BUFFERED_IMAGE_FACTORY,
new ManagedImageBufferedImageFactory());
BufferedImage image = Imaging.getBufferedImage(file, params);
你能给我一个代码片段吗?我被困了 6 个小时,Google 不想帮助我:-p
最佳答案
好的!我自己结束我的问题:-P
我终于找到了一 jar Java Advanced Imaging。 JAI解决了我的问题。
以下代码能够加载任意数量、任意深度的 TIFF 或 BMP 图像。
RenderedOp op = JAI.create("fileload", filename);
// gets the number of channels (R / RGB / RGBA)
channels = op.getColorModel().getNumColorComponents();
// gets the depth of each component (16 16 16)
depth = new int[channels];
for(int i=0; i<op.getColorModel().getNumColorComponents(); i++)
{
depth[i] = op.getColorModel().getComponentSize(i);
}
// gets the BufferedImage
image = op.getAsBufferedImage();
谢谢!!
关于java - 读取14位和16位图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12053942/