Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:14:21+00:00 2026-06-10T10:14:21+00:00

NET library a retrieve count of pages in multi tiff. I use sample from

  • 0

NET library a retrieve count of pages in multi tiff. I use sample from
http://bitmiracle.com/libtiff/help/retrieve-number-of-pages-in-tiff-image.aspx.

    public int GetNumberOfPages(Tiff image)
    {
        int pageCount = 0;
        do
        {
            ++pageCount;
        } while (image.ReadDirectory());

        return pageCount;
    }

    [TestMethod]
    public void GetNumberOfPages()
    {
        using (Tiff tiffFromFile = Tiff.Open(@"test.tif", "r"))
        {
            int numberOfPages = GetNumberOfPages(tiffFromFile);
        }

    }

I get exception: Cannot write to a closed TextWriter.

StackTrace:

at System.IO.__Error.WriterClosed()
   at System.IO.StringWriter.Write(String value)
   at Microsoft.VisualStudio.TestTools.TestTypes.Unit.ThreadSafeStringWriter.Write(String value)
   at System.IO.TextWriter.Write(String format, Object arg0)
   at System.IO.TextWriter.SyncTextWriter.Write(String format, Object arg0)
   at BitMiracle.LibTiff.Classic.TiffErrorHandler.WarningHandler(Tiff tif, String method, String format, Object[] args)
   at BitMiracle.LibTiff.Classic.Tiff.WarningExt(Tiff tif, Object clientData, String method, String format, Object[] args)
   at BitMiracle.LibTiff.Classic.Tiff.ReadDirectory()

The code is identical from sample. I can’t find root of this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:14:22+00:00Added an answer on June 10, 2026 at 10:14 am

    I would guess that the problem may be related to an unsupported image type or errors in the tiff file you are passing it. The LibTiff docs talk about adding a custom handler if you want to respond to errors. Not having used that library before, I can’t say for certain what happened. I would guess that maybe there was an error in the Open, but without having a handler, it ate the error. Then when you try to ReadDirectory the file is already closed. This is just a guess. I would recommend you add an error handler and see what is going on.

    http://bitmiracle.com/libtiff/help/tiff.seterrorhandler.aspx

    EDIT:

    I looked back at the sample page. They actually give two ways of reading the number of pages. Have you tried the simpler way to see if that fails the same way?
    To calculate number of pages in a TIFF image the Tiff.NumberOfDirectories() method or a simple loop that traverses directories can be used. This sample shows both methods.

    You should be able to turn your method into this:

    public short GetNumberOfPages(Tiff image)
    {
        return image.NumberOfDirectories()
    }
    

    If you are still having issues, try a different image that you know is valid and has multiple pages so that you can rule out the image issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this example of the WMI: http://msdn.microsoft.com/en-us/library/aa390423%28v=vs.85%29.aspx I retrieved information from the
I'm using DotNetOpenAuth ( http://dotnetopenauth.net/ ) library to authenticate at linkedIn.com . I develop
in ext.net library, how can I get from server side code the double clicked
I'm trying to use ServletContext.getResource to retrieve a java.net.url reference to an image file
I am looking for a .Net class/library to use with currency acronyms in the
I am looking for a library that can be used in .NET to retrieve
Hy, I am retrieving mails from a gmail account programaticaly using this libraries http://mailsystem.codeplex.com/
NET library that calculates the inverse erf() function in the normal distribution? Do you
I want sell some .NET library and I want provide edition with full source
Is there C# (.NET) library for Lego Mindstorm NXT, which is up-to-date? NXT.NET for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.