-1

I'm writing a java program to convert the tiff files to separate images , However I'm not able to use ImageDecoder as my tiff files doesn't contains II* as the starting , My tiff file starts with some header then the images starts with II* . Please advise how to remove the header part before II* in tiff images . Below is the code that I'm using to seperate the images , However I hit exception as below due to tiff not start with II*

 Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).

below is my method to seperete the images from 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();
Vinoth
  • 63
  • 4
  • 23
  • And after three attempts you will finally get it http://stackoverflow.com/questions/38431971/in-java-exclude-a-string-while-encode-using-base64 http://stackoverflow.com/questions/38380277/split-tiff-files-to-multiple-files http://stackoverflow.com/questions/38418111/unable-to-encode-a-tiff-file-properly-some-characters-are-not-encoding – gpasch Jul 21 '16 at 01:46

1 Answers1

0

I'm able to do using DataInputStream and DataOutputStream .

Using byte array to store and read by characters in for loop .

Vinoth
  • 63
  • 4
  • 23