如何打开 tiff 文件并删除 header 部分

How to open tiff file and remove the header part

我正在编写一个 java 程序来将 tiff 文件转换为单独的图像,但是我无法使用 ImageDecoder,因为我的 tiff 文件不包含 II* 作为起始,我的 tiff文件以一些 header 开头,然后图像以 II* 开头。请告知如何删除 tiff 图像中 II* 之前的 header 部分。 下面是我用来分隔图像的代码,但是由于 tiff 不是以 II*

开头,所以我遇到了如下异常
 Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).

下面是我从 tiff 中分离图像的方法。

  FileSeekableStream ss = new  FileSeekableStream("D:\Users\Vinoth\workspace\Testing\Testing.tif");
  ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
    int count = dec.getNumPages();
    TIFFEncodeParam param = new TIFFEncodeParam();

    param.setLittleEndian(false); // Intel
    System.out.println("This TIF has " + count + " image(s)");
    for (int i = 0; i < count; i++) {
        RenderedImage page = dec.decodeAsRenderedImage(i);
        File f = new File("D:\Users\Vinoth\workspace\Testing\single_" + i + ".tif");
        System.out.println("Saving " + f.getCanonicalPath());
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(page);
        pb.add(f.toString());
        pb.add("tiff");
        pb.add(param);
        RenderedOp r = JAI.create("filestore",pb);
        r.dispose();

我可以使用 DataInputStream 和 DataOutputStream 来完成。

在for循环中使用字节数组按字符存储和读取。