Click here to Skip to main content
6,822,613 members and growing! (16,523 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate License: The Code Project Open License (CPOL)

Save images into a multi-page TIFF file or add images to an existing TIFF file

By bijulsoni

Describes how to save images into a multi-page TIFF file and append images to an existing TIFF file by applying CCITT4 compression.
C#, .NET, WinXP, Visual-Studio, GDI+, Dev
Posted:27 Dec 2006
Views:99,193
Bookmarked:54 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
14 votes for this article.
Popularity: 5.08 Rating: 4.43 out of 5

1
1 vote, 7.1%
2

3
2 votes, 14.3%
4
11 votes, 78.6%
5

Load Image

Introduction

This article describes a way for saving images into the multi-page TIFF format by applying CCITT4 compression. It also explains how to append images to existing single page or multi-page TIFF files. Before that, we will understand what is tiff and why we should use the TIFF format.

What is TIFF ?

Tagged Image FIle Format (TIFF) is a highly used file format for storing images in many image processing applications. Using TIFF, we can store several images either as a single page or as a multi-page TIFF file. We can also append new images to existing single page or multi-page TIFF files. Many compressions like CCITT3, CCITT4, are also applied to TIFF files. Image related data like scanner name, compression type, bits per pixel, and host computer name are also stored in TIFF files using tags. Due to all these benefits, TIFF files are highly used in many applications.

You can download the sample code. The sample code attached with this article shows the following two things:

  1. How to store multiple images into single multi-page TIFF file with CCITT4 compression.
  2. How to append multiple images to existing single page or multi-page TIFF files with CCITT4 compression.

The reason for storing images with the CCITT4 compression is because programmers, initially, while playing with TIFF, generally face many problems when trying to store images with the CCITT4 compression using .NET. The most common error message is "Invalid Parameter". The most probable reason for this error is that the image on which you are trying to apply CCITT4 compression is not a bi-tonal image. The CCITT4 compression is applicable to bi-tonal images only. So I have given code for converting an image to a bi-tonal image. The code given in the sample application uses .NET GDI+ classes for storing images.

How to store images into a single multi-page TIFF file with CCITT4 compression

Consider the following screen:

Load Image

You can load as many images as you want by clicking the Load Images button. All these images will be shown in panels. Now, you can click the SaveAsMultipage button. A save file dialog will open, and you can specify file name and click on the Save button. If all images are successfully saved, then a message box will appear with the message "all images saved successfully". :) 

How to append multiple images to existing single page or multi-page TIFF files

You can load as many images as you want by clicking the Load Images button. All these images will be shown in panels. Now you can click the AddtoExistingFile button. An open file dialog will open and you can specify a file name by selecting any TIFF file from the file system and clicking on the Save button. If all images are successfully saved, then a message box will appear with the message "all images saved successfully".

Explanation of Code

All the above operations are done by following three functions

  • public bool saveMultipage(Image[] bmp, string location, string type)

    This function is responsible for receiving an array of images and for saving these images on the target location in multi-page TIFF file format.

  • public bool saveToExistingFile(string fileName, Image[] bmp, string type)

    This function is responsible for appending an array of images on an existing TIFF file which is specified by the file name parameter.

  • public Bitmap ConvertToBitonal(Bitmap original)

    This function takes a Bitmap object which is a non-bitonal image and converts that image into a bitonal image. This is required to apply CCITT4 compression. We can not apply CCITT4 compression on non-bitonal Images.

License

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

About the Author

bijulsoni


Member

Occupation: Software Developer
Company: Microsoft
Location: United States United States

Other popular GDI+ articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 48 (Total in Forum: 48) (Refresh)FirstPrevNext
GeneralNeed help. PinmemberMember 41261493:54 8 Oct '09  
GeneralNeed Your suggestion Pinmemberraju_Code20:42 30 Sep '09  
GeneralSpecific DPI PinmembernKognito0:33 15 Apr '09  
GeneralRe: Specific DPI Pinmemberdaelin14:32 24 Apr '09  
QuestionWhat about ColoR????????? help me please PinmemberAP080:58 25 Feb '09  
AnswerRe: What about ColoR????????? help me please Pinmemberbijulsoni9:55 25 Feb '09  
QuestionHow can I convert color images to grayscale images ? Pinmemberjlarini2:52 13 Feb '09  
QuestionImage Quality is reducing Pinmembercnataraj1:48 2 Jan '09  
GeneralIdentify Negative Tiff image and convert PinmemberMember 41803743:31 29 Oct '08  
Generalawesome! PinmemberDave Willemssen14:16 21 Oct '08  
QuestionAdjusting the DPI PinmemberRobDog88811:40 28 Mar '08  
GeneralRe: Adjusting the DPI Pinmemberbijulsoni13:16 28 Mar '08  
GeneralRe: Adjusting the DPI PinmemberRobDog88813:38 28 Mar '08  
GeneralRe: Adjusting the DPI Pinmemberjhornb8:03 24 Apr '08  
GeneralRe: Adjusting the DPI Pinmemberjimbpoe8:49 20 Jun '08  
GeneralThanks for helping with my faxing Pinmemberrolftheviking22:34 26 Sep '07  
GeneralNice code PinmemberWynt10:48 9 Aug '07  
GeneralRe: Nice code Pinmemberbijulsoni11:04 9 Aug '07  
GeneralRe: Nice code [modified] PinmemberWynt4:03 14 Aug '07  
GeneralRe: Nice code [modified] PinmemberWynt5:40 14 Aug '07  
GeneralProblem with stand-alone tiff file Pinmemberjosepaulino17:54 25 Mar '07  
GeneralRe: Problem with stand-alone tiff file Pinmemberbijulsoni19:27 25 Mar '07  
GeneralRe: Problem with stand-alone tiff file PinmemberTim McCurdy8:29 13 Apr '07  
GeneralSaving bitonal TIFFs Pinmembergcorgnet17:10 21 Mar '07  
GeneralRe: Saving bitonal TIFFs Pinmemberbijulsoni18:06 21 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 27 Dec 2006
Editor: Smitha Vijayan
Copyright 2006 by bijulsoni
Everything else Copyright © CodeProject, 1999-2010
Web11 | Advertise on the Code Project