Click here to Skip to main content
13,089,386 members (63,020 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 29 Sep 2007

Converting to TIFF

, 29 Sep 2007
Rate this:
Please Sign up or sign in to vote.
This article will help you convert imgaes of different formats to TIFF format.

Screenshot - Gova_s_ImgConverter.jpg


Conversion between different graphical image formats using C# and the .NET Framework is very common. This article focuses on the requirement of OCR and can be used as a pre-requirement component to build OCR.


I started working on OCR and was collecting information, and I came across an important thing: it can read embedded text information from image files which can be of a different format, but it can perform and achieve the required level of accuracy when the images are of the TIFF image format. This article focuses on this point and converts images of different formats to TIFF format.

Using the Code

The article is simple and the code is very easy to use.

This article has two main functions:

  • Open images
  • Convert images to .Tiff format.

The images which need to be converted can be opened by pressing the "Open" button on the application.

Code for Open button:
private void btnOpen_Click(object sender, EventArgs e)
    openFileDialog1.Title = "Open Image File";
    openFileDialog1.Filter = "Bitmap Files|*.bmp" +
        "|Enhanced Windows MetaFile|*.emf" +
        "|Exchangeable Image File|*.exif" +
        "|Gif Files|*.gif|Icons|*.ico|JPEG Files|*.jpg" +
        "|PNG Files|*.png|TIFF Files|*.tif|Windows MetaFile|*.wmf";
    openFileDialog1.DefaultExt = "bmp";
    openFileDialog1.FilterIndex = 1;
    openFileDialog1.FileName = "";
    if (openFileDialog1.FileName == "")
    CurrentFile = openFileDialog1.FileName.ToString();
    img = Image.FromFile(openFileDialog1.FileName);
    pictureBox1.Image = img;
    textBox1.Text = CurrentFile;

Once the image which needs to be converted is opened, you can continue with the process of conversion by pressing the "SaveAs Tiff" button on the application. Here, the processing proceeds by checking the image format, and then by using the wide range of functionalities provided by .NET, the image is converted to TIFF format.

Code for SaveAs TIFF button:
private void btnSave_Click(object sender, EventArgs e)
    string newName = System.IO.Path.GetFileNameWithoutExtension(CurrentFile);
    newName = newName + ".tif";
    if (System.IO.Path.GetExtension(CurrentFile).ToUpper().Contains(".TIF"))
        MessageBox.Show("Image file saved to " + newName.ToString(), 
            "Image Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        img.Save(newName, ImageFormat.Tiff);
    catch (Exception ee)
        string error = ee.Message.ToString();
        MessageBox.Show("Failed to save image to TIFF format.", "Error", 
            MessageBoxButtons.OK, MessageBoxIcon.Error);
    MessageBox.Show("Image file saved to " + newName.ToString(), 
        "Image Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
    textBox2.Text = System.IO.Path.GetFullPath(newName.ToString());

Once the image is converted, you can continue processing and then extract the embedded text from the image.

Points of Interest

Extracting the embedded text information from .tiff images increases the accuracy for OCRs.

Good luck guys!


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


About the Author

Govardhana Reddy
Web Developer India
India India
This is Govardhana Reddy, i am here to explore this world of INTERNET. I feel this is one way through which i can explore this world of INTERNET.

I want to be one among the best in this profession (a Software Developer, not a Software Engineer its a bit Controversial.) if not the "BEST"

My definition of a Software Engineer : "A person who knows what to cut/copy and where to paste".

Apart from my technical stuff I love Long Drives, Computer Gaming, Sports, Bikes and much more to say.

Anyways long road ahead keep me accompanied...

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
acosmin2-Sep-09 12:12
memberacosmin2-Sep-09 12:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 30 Sep 2007
Article Copyright 2007 by Govardhana Reddy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid