Java 如何打开tiff文件并删除标题部分

Java 如何打开tiff文件并删除标题部分,java,inputstream,tiff,endianness,javax.imageio,Java,Inputstream,Tiff,Endianness,Javax.imageio,我正在编写一个java程序,将tiff文件转换为单独的图像,但是我无法使用ImageDecoder,因为我的tiff文件不包含II*作为起始,我的tiff文件以某个头开始,然后图像以II*开始。请建议如何删除tiff图像中II*之前的标题部分。 下面是我用来分隔图像的代码,但是由于tiff不是以II开头,我遇到了如下异常* Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not

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

 Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
  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();
下面是我从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();
FileSeekableStream ss=newfileseekablestream(“D:\\Users\\Vinoth\\workspace\\Testing\\Testing.tif”);
ImageDecoder dec=ImageCodec.createImageDecoder(“tiff”,ss,null);
int count=dec.getNumPages();
TIFFEncodeParam param=新的TIFFEncodeParam();
参数setLittleEndian(假);//英特尔
System.out.println(“此TIF具有“+计数+”图像)”;
for(int i=0;i
我可以使用DataInputStream和DataOutputStream

  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();

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

三次尝试后,您将最终获得它
  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();