我有一个平铺的图像。我能够读取元数据,所以我知道瓷砖尺寸;但我不知道如何阅读特定的瓷砖。我有这些问题:
假设我的tiff由128x128磁贴组成,如何读取位于0,0(x,y)的磁贴?
我的tiff文件中有多少个图块?
我尝试开发一个代码来管理单个磁贴,但我不知道如何识别特定的磁贴位置。
IImageMetadata metadata = Sanselan.getMetadata(imageFile);
TiffDirectory tiffDirectory = ((TiffImageMetadata) metadata).findDirectory(TiffDirectoryConstants.DIRECTORY_TYPE_ROOT);
ByteSourceFile byteSource = new ByteSourceFile(imageFile);
ArrayList<?> elements = tiffDirectory.getTiffRawImageDataElements();
TiffImageData.Data data[] = new TiffImageData.Data[elements.size()];
for (int i = 0; i < elements.size(); i++) {
TiffDirectory.ImageDataElement element = (TiffDirectory.ImageDataElement) elements.get(i);
byte bytes[] = byteSource.getBlock(element.offset, element.length);
data[i] = new TiffImageData.Data(element.offset, element.length, bytes);
}
TiffField tileWidthField = tiffDirectory.findField(TiffTagConstants.TIFF_TAG_TILE_WIDTH);
if (null == tileWidthField)
throw new ImageReadException("Can't find tile width field.");
int tileWidth = tileWidthField.getIntValue();
TiffField tileLengthField = tiffDirectory.findField(TiffTagConstants.TIFF_TAG_TILE_LENGTH);
if (null == tileLengthField)
throw new ImageReadException("Can't find tile length field.");
int tileLength = tileLengthField.getIntValue();
TiffImageData.Tiles tile = new TiffImageData.Tiles(data, tileWidth, tileLength);
我正在使用Apache孵化器中的Sanselan来进行这些操作。
答案 0 :(得分:1)
TIFF图块按行主要顺序排列,因此可以相对简单地确定需要阅读的图块。对于您的具体问题,(0,0)处的图块是图块#0。平铺的数量来自:
Horizontal_Tiles = (Image_Width + Tile_Width-1)/Tile_Width;
Vertical_Tiles = (Image_Height + Tile_Height-1)/Tile_Height;
Total_Tiles = Horizontal_Tiles * Vertical_Tiles;