Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like the <a href="http://www.fileformat.info/format//tiff/corion.htm" rel="nofollow">tiff file format</a> groups this information together in a header, so you could just read the data from the file yourself:</p> <pre><code>private static Dimension getTiffDimensions(InputStream tiffFile) throws IOException { ReadableByteChannel channel = Channels.newChannel(tiffFile); ByteBuffer buffer = ByteBuffer.allocate(12); forceRead(channel, buffer, 8); byte endian = buffer.get(); if(endian != buffer.get() || (endian != 'I' &amp;&amp; endian != 'M')) { throw new IOException("Not a tiff file."); } buffer.order(endian == 'I' ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); if(buffer.getShort() != 42) { throw new IOException("Not a tiff file."); } // Jump to the first image directory. Note that we've already read 8 bytes. tiffFile.skip(buffer.getInt() - 8); int width = -1; int height = -1; // The first two bytes of the IFD are the number of fields. forceRead(channel, buffer, 2); for(int fieldCount = buffer.getShort(); fieldCount &gt; 0 &amp;&amp; (width &lt; 0 || height &lt; 0); --fieldCount) { forceRead(channel, buffer, 12); switch(buffer.getShort()) { case 0x0100: // Image width width = readField(buffer); break; case 0x0101: // Image "length", i.e. height height = readField(buffer); break; } } return new Dimension(width, height); } private static void forceRead(ReadableByteChannel channel, ByteBuffer buffer, int n) throws IOException { buffer.position(0); buffer.limit(n); while(buffer.hasRemaining()) { channel.read(buffer); } buffer.flip(); } private static int readField(ByteBuffer buffer) { int type = buffer.getShort(); int count = buffer.getInt(); if(count != 1) { throw new RuntimeException("Expected a count of 1 for the given field."); } switch(type) { case 3: // word return buffer.getShort(); case 4: // int return buffer.getInt(); default: // char (not used here) return buffer.get() &amp; 0xFF; } } </code></pre> <p>I've tested this with a few different tiff files (run length encoded black &amp; white, color with transparency) and it seems to work fine. Depending on the layout of your tiff file it may have to read a lot of the stream before it finds the size (one of the files I tested, saved by Apple's Preview, had this data at the end of the file).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload