Forum Discussion

rminnich's avatar
rminnich
Contributor
14 years ago

multi-page tiff

Can TestComplete 8 compare multiple pages within a multipage TIFF against another multi-page TIFF?  If I load a multi-page TIFF into test complete using the Picture.LoadFromFile command, the size becomes 1600x1200, which leads me to believe that it is loading a single page.



My scenario is the following.

During my test, I would print out a several page report and print it to a multi-page TIFF.  I would like to compare each page (image) in the TIFF with a baseline version of the TIFF.  Is this possible using only the functionality in TestComplete?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm not sure if the "Picture" option is necessarily the best object to use.  For that matter, I'm not sure the "Regions" one is, either.  Both of those objects, from what I peruse in the help docs, are geared towards testing images from a screen shot or something that is typically single page.



    You might have to do just a raw file byte to byte comparison if you want to use what's in TC natively.  Otherwise, you'll have to write custom automation code to compare these kinds of custom TIFF files.
  • I ended up writing some custom code to do this.  I was hoping that TestComplete would be able to do the comparison automatically or allow me to pass in which page of each picture to compare.



    I ended up writing a class in C# (yay for the CLR bridge) that extracted individual pages and stored them as PNGs.  Now I can use Picture compare and difference in my testing.



    I wanted to use the built in compare functions so I could use transparency to ignore variances, such as date/time values.

  • Hello Russell,





    You are right - TestComplete can't do this. We have a corresponding suggestion in our DB, so your post has increased it rating. Thanks!





    And that's great to hear you have managed to implement your own solution! Would you mind posting your code here? It may be very useful for other TestComplete users.
  • Here is the class that I created for TIFF extraction.  It is a work in progress.  It's sole purpose is to allow you to extract arbitrary pages from a multipage TIFF and store it as a single page image.  It supports both Tiffs and PNGs, although I'm not sure there is a such a thing as a multipage PNG. 



    I use this class in TC vis the CLR bridge.



    Usage: Use the static CreateWrappedTiff method to create a WrappedTiff.  It takes the path filename of the multipage TIFF.  I did this because I find using constructors in .NET classes to be rather painful in TC.



    Use the NumPages method on a WrappedTiff instance to get the number of pages in the file.

    Use ExtractPage to extract a page from the TIFF.  It saves the image at the specified index (0-based) to the filename specified.



    After extracting all the images you want, call Destroy() on the object to release the bitmap and stream associated with the input file.  (This should probably use dispose).



    I used TC to do the actual image comparisons by creating various Picture objects and comparing those.



    using System.Drawing;

    using System.Drawing.Imaging;

    using System.IO;


    public class WrappedTiff

        {


            Bitmap b;

            Stream bitmapStream;

            ImageFormat format;

           

            public static WrappedTiff CreateWrappedTiff(string filename)

            {

                WrappedTiff w = new WrappedTiff();

                // Bitmap.FromFile doesn't release the file after reading, read from a stream instead

                 w.bitmapStream = File.OpenRead(filename);

                w.b = (Bitmap)Bitmap.FromStream(w.bitmapStream);


                if (filename.ToUpper().EndsWith(".TIF"))

                {

                    w.format = ImageFormat.Tiff;

                }

                else

                {

                    w.format = ImageFormat.Png;

                }


                return w;

            }


            public int NumPages()

            {

                return b.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

            }


            public bool ExtractPage(string outputfile, int page)

            {

                if (page >= NumPages())

                {

                    return false;

                }


                b.SelectActiveFrame(FrameDimension.Page, page);

                b.Save(outputfile, this.format);


                return true;


            }


            public void Destroy()

            {

                bitmapStream.Close();

                b = null;

            }

        }



  • using System.IO;
    using System.Drawing.Printing;
    using RasterEdge.Imaging;
    using RasterEdge.Imaging.Processing;
    using RasterEdge.Imaging.MultipageTiff;

    see more tutorails on Multi-page tiff processing in c#.net
    Sample codes for creating an editable multi-page tiff,saving,delate,add a page in multipage tiff pages


     



    aving