Tiff Tiled:如何读取特定的图块?

| 我有一个平铺的图像。我能够读取元数据,所以我知道磁贴的尺寸;但我不知道如何读取特定的图块。我有这些问题: 假设我的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进行这些操作。     
已邀请:
        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;
    

要回复问题请先登录注册