JAI FormatDescriptor图像变为白色

时间:2014-11-11 10:32:15

标签: image overlay jai

我想用两张图片进行叠加操作。这些图像的波段数和数据类型必须相同,因此我可以执行重叠操作。因此,我使用FormatDescriptor将一个图像的数据类型更改为另一个图像的数据类型。但现在图像全是白色。

这是正常的吗?或者我在FormatDescriptor

中有错误

以下是重新格式化的代码:

RenderedImage finalImage = loadTiles(i, columns, rows);           
// Format Image so that the data type matches that of the overlay
finalImage = FormatDescriptor.create(finalImage, overlay.getSampleModel().getDataType(), null);
images.add(finalImage); 
columns = roundUp(columns, 2); 
rows = roundUp(rows, 2);

感谢您的帮助。

编辑我尝试格式化叠加层,使其与图像的数据类型相匹配。这样就可以正确显示图像,但叠加层完全是黑色的。

普通数据类型如下:

image:数据类型= 1(ushort)

overlay:数据类型= 0(字节)

编辑我还尝试将图像重新格式化为其他所有数据类型。每次我得到相同的结果。图像全是白色的。除非我尝试格式化以缩短。然后我得到NullPointerException

我不知道,我做错了什么。我发现了许多使用格式化操作的不同例子,我以同样的方式使用它。但是当重新格式化时我得到白色图像时,使用格式化操作有什么意义呢?是否有其他方法可以更改图像的数据类型,因此它与叠加层的数据类型相匹配?

1 个答案:

答案 0 :(得分:0)

好的,我想出了一种改变图像数据类型的不同方法。可以使用LookupTableJAI。下面是我用来转换图像的代码:

byte[] tableData = new byte[0x10000];
for (int j = 0; j < 0x10000; j++) {
    tableData[j] = (byte)(j >> 8);
}

LookupTableJAI table = new LookupTableJAI(tableData);
finalImage = JAI.create("lookup", finalImage, table);
相关问题