Click here to Skip to main content
15,881,803 members
Articles / Multimedia / GDI+
Article

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

Rate me:
Please Sign up or sign in to vote.
4.68/5 (28 votes)
27 Dec 2006CPOL3 min read 422.6K   18.2K   92   72
Describes how to save images into a multi-page TIFF file and append images to an existing TIFF file by applying CCITT4 compression.

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)


Written By
Software Developer Microsoft
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: What about ColoR????????? help me please Pin
bijulsoni25-Feb-09 8:55
bijulsoni25-Feb-09 8:55 
GeneralRe: What about ColoR????????? help me please Pin
Reza Nabiloo29-Jan-18 1:22
Reza Nabiloo29-Jan-18 1:22 
QuestionHow can I convert color images to grayscale images ? Pin
jlarini13-Feb-09 1:52
jlarini13-Feb-09 1:52 
QuestionImage Quality is reducing Pin
cnataraj2-Jan-09 0:48
cnataraj2-Jan-09 0:48 
GeneralIdentify Negative Tiff image and convert Pin
Member 418037429-Oct-08 2:31
Member 418037429-Oct-08 2:31 
Generalawesome! Pin
Dave Willemssen21-Oct-08 13:16
Dave Willemssen21-Oct-08 13:16 
QuestionAdjusting the DPI Pin
RobDog88828-Mar-08 10:40
RobDog88828-Mar-08 10:40 
GeneralRe: Adjusting the DPI Pin
bijulsoni28-Mar-08 12:16
bijulsoni28-Mar-08 12:16 
Thanks for your appreciation.
To answer your question,
You are getting resulting image with 96DPI but you want it to be 300DIP.
I am not able to understand why it is reducing DPI 96DIP from 300DPI. Can you please try to print your origional image's DPI value before applying any compression. I have the doubts that your image itself is having 96DPI.
I dont know about a way to set DPI for an image but if i get something, i will surely post it.
Thanks
Bijul Soni
GeneralRe: Adjusting the DPI Pin
RobDog88828-Mar-08 12:38
RobDog88828-Mar-08 12:38 
GeneralRe: Adjusting the DPI Pin
jhornb24-Apr-08 7:03
jhornb24-Apr-08 7:03 
GeneralRe: Adjusting the DPI Pin
jimbpoe20-Jun-08 7:49
jimbpoe20-Jun-08 7:49 
GeneralThanks for helping with my faxing Pin
rolftheviking26-Sep-07 21:34
rolftheviking26-Sep-07 21:34 
GeneralNice code Pin
Wynt9-Aug-07 9:48
Wynt9-Aug-07 9:48 
GeneralRe: Nice code Pin
bijulsoni9-Aug-07 10:04
bijulsoni9-Aug-07 10:04 
GeneralRe: Nice code [modified] Pin
Wynt14-Aug-07 3:03
Wynt14-Aug-07 3:03 
GeneralRe: Nice code [modified] Pin
Wynt14-Aug-07 4:40
Wynt14-Aug-07 4:40 
GeneralProblem with stand-alone tiff file Pin
josepaulino25-Mar-07 16:54
josepaulino25-Mar-07 16:54 
GeneralRe: Problem with stand-alone tiff file Pin
bijulsoni25-Mar-07 18:27
bijulsoni25-Mar-07 18:27 
GeneralRe: Problem with stand-alone tiff file Pin
Tim McCurdy13-Apr-07 7:29
Tim McCurdy13-Apr-07 7:29 
GeneralSaving bitonal TIFFs Pin
gcorgnet21-Mar-07 16:10
gcorgnet21-Mar-07 16:10 
GeneralRe: Saving bitonal TIFFs Pin
bijulsoni21-Mar-07 17:06
bijulsoni21-Mar-07 17:06 
GeneralRe: Saving bitonal TIFFs Pin
Dave Willemssen3-Nov-08 11:29
Dave Willemssen3-Nov-08 11:29 
Generalmultipage tif from *.tif and *.jpg Pin
Member 393399918-Mar-07 5:52
Member 393399918-Mar-07 5:52 
GeneralProblem when converting to vb.net 2005 code Pin
gaigoi11317-Mar-07 5:07
gaigoi11317-Mar-07 5:07 
GeneralRe: Problem when converting to vb.net 2005 code Pin
bijulsoni17-Mar-07 6:53
bijulsoni17-Mar-07 6:53 

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.