LibTiff.Net is ready for you

Hello!

I’m pleased to announce that we’ve completed LibTiff.Net. It is free and open source version (port) of classic LibTiff written using C#.

License is practically the same as for LibTiff. API is very close to original one. Code is fully managed.

LibTiff.Net was developed with a goal to produce images that are byte-to-byte equal to images produced by LibTiff-3.9.4.

You can download binaries or source code with tests here:
https://bitmiracle.com/libtiff/

Differences (mostly renames of function names and types) between
LibTiff.Net and LibTiff-3.9.4 are described here.

Following codecs are implemented:
LZW, Packbits, Jpeg (using our own LibJpeg.Net), all CCITT versions, Deflate, Adobe Deflate

I hope you will find LibTiff.Net useful. Please write us if you have any questions or find any bugs.

29 Responses to “LibTiff.Net is ready for you”

  • Hi,
    thank you for this great Library. It’s amazing.

    Anyway I got a question.. Is there an example how to merge 2 or more tif files to 1 file?

    Thanks in advance
    Milaim ajdari

  • Hello Milaim!

    Thank you for your warm words!

    For merging two or more tif files to one compound tif file you can use TiffCP console utility (it’s a part of LibTiff.Net). Pass paths to original files as first parameters and then pass path to result file as last parameter.

    E.g. “TiffCP.exe 1.tif 2.tif result.tif”
    This command creates “result.tif” image with two pages.

    You may want to take a look at TiffCP source code if you want to merge files from your code. TiffCP source code is distributed along with LibTiff.Net source code.

    Best regards,
    Vitaliy Shibaev

  • Hi,

    It would be nice if you can provide some C# or VB.NET samples. It is sometime hard to follow C++ code 🙂

    Samples like browsing multi page tiff file, adding pages, saving, deleting etc using your excellent library.

    Thanks,
    Dadaji

  • Thank you for your comment, Dadaji

    We’ll definitely add samples to the LibTiff library. Actually, it planned for the next release.

  • It’s great!

    I am waiting for such a library so long time. Now I begin to wait for next release and the samples.

    Thank you very much!

  • hi!!!

    I want to know, if i can develop with LIBTIF .NET applications in VISUAL BASIC .NET, Not in C#.

  • Hello Antony,

    sure you can.

  • Kevin Nguyen

    Sergius,
    can you show me how to convert tiff to pdf and preserves the color. I tried this in C# and it works but i can’t read the file. the file is fuzzy.

    Dim listn As New List(Of String)
    listn.Add(“-o”)
    listn.Add(“C:\Users\hnguyen.TRANSLOG\Desktop\lg1.pdf”)
    listn.Add(“C:\Users\hnguyen.TRANSLOG\Desktop\lg1.tif”)
    BitMiracle.Tiff2Pdf.Program.g_testFriendly = True
    BitMiracle.Tiff2Pdf.Program.Main(listn.ToArray())

    I tried this and it doesn’t work
    Dim listn As New List(Of String)(2)
    listn.Add(“-x 100”)
    listn.Add(“-l 100”)
    listn.Add(“-o”)
    listn.Add(“C:\Users\hnguyen.TRANSLOG\Desktop\lg1.pdf”)
    listn.Add(“C:\Users\hnguyen.TRANSLOG\Desktop\lg1.tif”)
    BitMiracle.Tiff2Pdf.Program.g_testFriendly = True
    BitMiracle.Tiff2Pdf.Program.Main(listn.ToArray())

    thank you in advance

  • Kevin,

    Your code should look something like this:
    Dim inputFile As String = "image.tif"
    Dim outputFile As String = "output.pdf"

    Dim arguments As String() = New String() {"-o", outputFile, "-x", "100", "-y", "100", inputFile}
    BitMiracle.Tiff2Pdf.Program.Main(arguments)

    But there is also a bug in version 1.1.2078.0 that won’t let this code to run properly. We are almost completed version 2.0 that does not contain the bug. You can write us using e-mail or support request form if you want to receive beta version of LibTiff 2.0

  • Kevin Nguyen

    Thank you for the quick respond Sergius. I just sent a request via email.

  • Karsten Wilson

    I’m interested in using your libtiff from vb.net, but I’m having some issues figuring out the syntax. All the examples I’ve seen are for C++ and libtiff… I can’t wait for the new version with some sample code!

    I do have a question. If I am handling a grayscale tiff, and I want to open the entire image into an array (w/o converting to RGB) do I need to do this 1 raster at a time with the readscanline function, or is there a better way?

    Thanks

  • Hello Karsten,

    Thank you for your interest in LibTiff.Net. You can write us using e-mail or support request form if you want to receive beta version of LibTiff 2.0.

    You can read entire image using various methods. There is ReadScanline that reads one scanline at a time. There is also ReadEncodedStrip (reads one strip at a time), ReadEncodedTile (reads one tile at a time), ReadTile and even ReadRawStrip and ReadRawTile if you want uncompressed data.

    And of course, you can use ReadRGBAImage, ReadRGBAImageOriented, ReadRGBAStrip and ReadRGBATile if you need to retrieve image data converted to RGB.

  • Is there a way to disable STRIPCHOP so that when I read the Tiff Tag ROWSPERSTRIP it will give me the true value even if all the rows are in one strip (ie a true 1 strip image tiff). If I use tiffinfo it tells me the “true” value of rows per strip (in my case 224 rows per strip).

    Could you make it so that this STRIPCHOP could be changed from C# to enabled or disabled?

    Thanks

  • Hello Neal,

    To disable STRIPCHOP you should use one of the open flags. Please take a look at
    http://bitmiracle.com/libtiff/help/tiff.open.aspx

    In your case you should use some thing like using (Tiff tif = Tiff.Open("file.tif", "rc")) { }

  • Hi,
    I am trying to use your wonderful library to open an existing multipage tiff file, and then replace a page in the middle of the file with a new tiff file that is provided at run time, or equivalently removing the page first, then inserting a new page beginning where the original one started. Can you provide me with an example on how to do this? I am doing it in .NET and my .NET skills are on the beginner scale.

  • Hi Bryce,

    Unfortunately, LibTiff.Net have no built-in methods for page removal or replacement. But you may use tiffcp utility to copy range of pages from existing TIFF file to a new one. Or you may use source code for tiffcp utility as a sample and build described functionality in our code.

    Please write us using e-mail (support@bitmiracle.com) if you have other questions or need any help.

  • Hi again. Sorry about the lack of data. I am using Visual Studio C# 2010 Express and there are other
    errors. My program is a sample:

    using System.Diagnostics;
    using System.IO;
    using System.Windows.Forms;

    using BitMiracle.LibTiff.Classic;

    namespace BitMiracle.LibTiff.Samples
    {
    public static class EnumerateTiffTags
    {
    public static void Main()
    {
    const string fileName = @”Sample data\multipage.tif”;

    using (Tiff image = Tiff.Open(fileName, “r”))
    {
    if (image == null)
    {
    MessageBox.Show(“Could not open incoming image”);
    return;
    }

    using (StreamWriter writer = new StreamWriter(“EnumerateTiffTags.txt”))
    {
    short numberOfDirectories = image.NumberOfDirectories();
    for (short d = 0; d < numberOfDirectories; ++d)
    {
    if (d != 0)
    writer.WriteLine("———————————");

    image.SetDirectory((short)d);

    writer.WriteLine("Image {0}, page {1} has following tags set:\n", fileName, d);
    for (ushort t = ushort.MinValue; t < ushort.MaxValue; ++t)
    {
    TiffTag tag = (TiffTag)t;
    FieldValue[] value = image.GetField(tag);
    if (value != null)
    {
    for (int j = 0; j < value.Length; j++)
    {
    writer.WriteLine("{0}", tag.ToString());
    writer.WriteLine("{0} : {1}", value[j].Value.GetType().ToString(), value[j].ToString());
    }

    writer.WriteLine();
    }
    }
    }
    }
    }

    Process.Start("EnumerateTiffTags.txt");
    }
    }
    }

    Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)

    Error 2 The type or namespace name 'Classic' does not exist in the namespace 'BitMiracle.LibTiff' (are you missing an assembly reference?)

    Error 3 The type or namespace name 'Tiff' could not be found (are you missing a using directive or an assembly reference?)
    Error 4 The name 'Tiff' does not exist in the current context
    Error 5 The name 'MessageBox' does not exist in the current context
    Error 6 The type or namespace name 'TiffTag' could not be found (are you missing a using directive or an assembly reference?)
    Error 7 The type or namespace name 'TiffTag' could not be found (are you missing a using directive or an assembly reference?)
    Error 8 The type or namespace name 'FieldValue' could not be found (are you missing a using directive or an assembly reference?)
    Error 9 The name 'Process' does not exist in the current context

  • bbnes,

    The amount of support for open source libraries is limited. Please have a look at this page:
    Limited support for free open source libraries and tools

  • Hello! This is a great library, thank you!!
    One thing though… Are there any methods/features to write TEXT to a TIFF file in LibTiff.NET?
    Or… are there any plans to add this?
    Or… is this the wrong question? How can I add text to my newly created TIFF file using LibTiff.NET with C#??? Thank you in advance!!

  • Hello David,

    Please have a look at Add custom TIFF tags to an existing TIFF image sample. The sample shows how to add text to a TIFF.

  • Sergius, that example does not show how to add text to the content of a tiff image. It’s only creating a tiff tag with that text.

    I’m also interested in adding text to a tiff using this library.

    Thanks.

  • I assume you are talking about drawing text on top of the image. Unfortunately, this is unsupported by the library. LibTiff.Net is actually more like codec than a full-blown imaging library.

    You might be better served by general-purpose libraries like FreeImage.Net.

  • hello, i’m trying to use this library for Tiff2Pdf conversion. I’m using Visual Studio 2012, C# language, I add the reference BitMiracle.LibTiff.NET to my project, add the line “using BitMiracle.LibTiff.Classic;” but when i try to use the converter by adding the line ” BitMiracle. Tiff2Pdf.Program.Main(arguments);” ( like in the Sample provided ) I end up with “The type or namespace name “Tiff2Pdf” does not exist in the namespace “BitMiracle” ( are you missing an assembly reference? ) . The only thing accesible is BitMiracle.LibTiff . Can someone please help me with a workaround?

  • nevermind, i forgot to add Tff2Pdf.exe to project References. Sorry for silly posting, please delete my post.

  • Hi Sergius,

    When I tried to use Tiff2Pdf to convert a color multiple page TIFF image into a PDF file, I received error message like “Warning, Photometric tag value assumed incorrect, assuming data is YCbCr instead of RGB”.

    Any idea about how to fix the above issue?

    Your library is great and I have been using it for more than 1 year in production. Just very great!

    Thanks in advance.

    Chile

  • Chile,

    Most probably your image contains Photometric.RGB as a value for TiffTag.PHOTOMETRIC tag. And the image data is encoded with JPEG compression and some other JPEG-related tags are set. The library decides that value for TiffTag.PHOTOMETRIC tag is incorrect and auto-corrects it.

    There is no way to fix the issue other than changing the tag value.

  • Got error while deploying
    “application validation is not succeed unable to continue “

  • Jason Lindquist

    I am using the tool to convert TIF to PDF and it works great most of the time. I recently encountered an issue that it is converting the pages in the incorrect order on some of my files. The files I am converting are assembled from multiple TIF files using Microsoft Document Imaging. The original files were created via scan or received via eFax. My guess is the tool is using the internal page number from the original document to some degree but I have been unable to find a pattern. I am using the Tiff2PDF conversion utility. If you have any suggestions please let me know.

    jason

  • Hello Jason,

    You are right, the Tiff2Pdf utility uses value of TiffTag.PAGENUMBER tag to find out the order of pages. So, the assembled files probably have wrong values set for the tag.

    To change the behavior of the utility you can either pre-process your TIFFs (set TiffTag.PAGENUMBER to 0 for all pages) or you can create custom version of the utility.

    In the code of the utility there is the cmp_t2p_page class. You can change it so it never compares page_number and only compares page_directory. This should give you the expected output.