0

I trying to process a TIFF file using Image class:

using System.Drawing

var i = Image.FromFile("in.tiff");
i.Save("out.tiff");

However, when I do it like this, out.tiff has only the first page of the multipage in.tiff. I know that the information about multiple pages is preserved under Image:

i.GetFrameCount(Imaging.FrameDimension.Page) // Returns 5, which is the number of pages

How can I save i as a full TIFF file instead of a part of it?

radrow
  • 6,419
  • 4
  • 26
  • 53
  • The following may be helpful: https://stackoverflow.com/questions/70336508/c-sharp-tesseract-only-scanns-first-tiff-page/70428633#70428633 – Tu deschizi eu inchid Apr 01 '22 at 14:52
  • From the remarks section: _If no encoder exists for the file format of the image, the Portable Network Graphics (PNG) encoder is used. When you use the Save method to save a graphic image as a Windows Metafile Format (WMF) or Enhanced Metafile Format (EMF) file, the resulting file is saved as a Portable Network Graphics (PNG) file._.... So you need to call an overload that defines the format. `i.Save("out.tiff", System.Drawing.Imaging.ImageFormat.Tiff);`. – dr.null Apr 01 '22 at 19:35
  • @dr.null Just tried and still only the first page is saved – radrow Apr 04 '22 at 09:34
  • There’s code in [this post](https://stackoverflow.com/questions/398388) that saves multi-page TIF. If that doesn’t work for you and you want to consider using a professional imaging library, try the [free evaluation of LEADTOOLS Imaging Pro](https://www.leadtools.com/downloads). (Disclosure: I work for its vendor). The code to load and save any multi-page format to compressed TIFF is simply `RasterImage img = rasterCodecs.Load("in.tiff", 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);` then `rasterCodecs.Save(img, "out.tiff", RasterImageFormat.TifLzw, 0, 1, -1, 1, CodecsSavePageMode.Append);`. – Amin Dodin Apr 04 '22 at 13:13
  • 1
    Right, I missed the multi-frames part. My bad. See [Convert bitmaps to one multipage TIFF image](https://stackoverflow.com/questions/398388/convert-bitmaps-to-one-multipage-tiff-image-in-net-2-0). – dr.null Apr 04 '22 at 14:12
  • 1
    Uh oh, looks like it's my first duplicate vote on my own question – radrow Apr 04 '22 at 19:07

0 Answers0