private void CompareTiffImages(byte[] cmpBytes, byte[] resultBytes) { int cmpNumDirectories = TIFFDirectory.GetNumDirectories(new RandomAccessFileOrArray(new RandomAccessSourceFactory ().CreateSource(cmpBytes))); int resultNumDirectories = TIFFDirectory.GetNumDirectories(new RandomAccessFileOrArray(new RandomAccessSourceFactory ().CreateSource(resultBytes))); NUnit.Framework.Assert.AreEqual(cmpNumDirectories, resultNumDirectories); for (int dirNum = 0; dirNum < cmpNumDirectories; ++dirNum) { TIFFDirectory cmpDir = new TIFFDirectory(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource (cmpBytes)), dirNum); TIFFDirectory resultDir = new TIFFDirectory(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource (resultBytes)), dirNum); NUnit.Framework.Assert.AreEqual(cmpDir.GetNumEntries(), resultDir.GetNumEntries()); NUnit.Framework.Assert.AreEqual(cmpDir.GetIFDOffset(), resultDir.GetIFDOffset()); NUnit.Framework.Assert.AreEqual(cmpDir.GetNextIFDOffset(), resultDir.GetNextIFDOffset()); NUnit.Framework.Assert.AreEqual(cmpDir.GetTags(), resultDir.GetTags()); foreach (int tag in cmpDir.GetTags()) { NUnit.Framework.Assert.AreEqual(cmpDir.IsTagPresent(tag), resultDir.IsTagPresent(tag)); TIFFField cmpField = cmpDir.GetField(tag); TIFFField resultField = resultDir.GetField(tag); if (tag == TIFFConstants.TIFFTAG_SOFTWARE) { CompareSoftwareVersion(cmpField, resultField); } else { CompareFields(cmpField, resultField); } } CompareImageData(cmpDir, resultDir, cmpBytes, resultBytes); } }
/// <summary>Gets the number of pages the TIFF document has.</summary> /// <param name="raf"> /// a /// <c>RandomAccessFileOrArray</c> /// containing a TIFF image. /// </param> /// <returns>the number of pages.</returns> public static int GetNumberOfPages(RandomAccessFileOrArray raf) { try { return(TIFFDirectory.GetNumDirectories(raf)); } catch (Exception e) { throw new iText.IO.IOException(iText.IO.IOException.TiffImageException, e); } }