Click here to Skip to main content
15,889,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking for some tools that will allow me to create a TIFF document and then save it to a folder. If there isn't any built in tools, please recommend an add-on package.

Thank you
Posted

.Net does not have great tools for handling the TIFF format built in, at work we use LibTiff.Net[^], which is free and open-source.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Feb-13 18:34pm    
Sure, a 5.
—SA
I actually started to look t this last week but couldn't get any support ( which I can understand since it's free). I am looking to create a laboratory report. In one of their examples they build a bridge.

C#
using BitMiracle.LibTiff.Classic;

namespace WriteTiff
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] buffer = new byte[25 * 144]
            {
                // boring hex omitted
            };

            // Open the TIFF file
            using (Tiff image = Tiff.Open("output.tif", "w"))
            {
                if (image == null)
                {
                    System.Console.Error.WriteLine("Could not open output.tif for writing");
                    return;
                }

                // We need to set some values for basic tags before we can add any data
                image.SetField(TiffTag.IMAGEWIDTH, 25 * 8);
                image.SetField(TiffTag.IMAGELENGTH, 144);
                image.SetField(TiffTag.BITSPERSAMPLE, 1);
                image.SetField(TiffTag.SAMPLESPERPIXEL, 1);
                image.SetField(TiffTag.ROWSPERSTRIP, 144);

                image.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
                image.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISWHITE);
                image.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
                image.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

                image.SetField(TiffTag.XRESOLUTION, 150.0);
                image.SetField(TiffTag.YRESOLUTION, 150.0);
                image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);

                // Write the information to the file
                image.WriteEncodedStrip(0, buffer, 25 * 144);

                // file will be auto-closed during disposal
                // but you can close image yourself
                image.Close();
            }
        }
    }
}



Let's say I want to create a TIFF file that contains says "Hello World" in bold. Can you please supply an example of how I would code this with LibTiff?

Thank you.
 
Share this answer
 
Comments
lewax00 12-Feb-13 19:11pm    
It's in an example that isn't obvious, but check: http://bitmiracle.com/libtiff/help/add-page-to-existing-tiff.aspx it shows how to render strings onto it. In the future, if you need clarification on an answer, please use the "Have a Question or Comment?" button below the answer it's in reference too, otherwise that person will not get a notification (I only checked back because I had a new comment from someone else). It works out better for everyone that way :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900