Click here to Skip to main content
15,878,748 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.5K   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

 
QuestionHow can I create multi-page tiff from 50000 images. Pin
Member 1132475030-Sep-19 0:50
Member 1132475030-Sep-19 0:50 
QuestionExcelente !!!!!!!!!!!!!!!!!!!!!! Pin
Luis Daniel Roman Velez6-Jun-18 5:43
Luis Daniel Roman Velez6-Jun-18 5:43 
QuestionHelp in converting pdf to multipage tiff and run as utility Pin
Rujj15-Feb-17 23:53
Rujj15-Feb-17 23:53 
QuestionThank you Pin
peterkmx11-Jun-15 22:06
professionalpeterkmx11-Jun-15 22:06 
Questionmismatch with image length Pin
Member 899016931-May-15 23:35
Member 899016931-May-15 23:35 
GeneralMy vote of 4 Pin
Silver1321-Apr-15 18:38
Silver1321-Apr-15 18:38 
QuestionTiff with jpeg compression Pin
Bharat_DCSL7-Oct-14 0:11
Bharat_DCSL7-Oct-14 0:11 
QuestionSolved a question that gave me near crazy Pin
marcelo.nicolet17-Jul-14 12:44
marcelo.nicolet17-Jul-14 12:44 
QuestionThank you Pin
Gustav Mulder16-Jul-14 4:07
Gustav Mulder16-Jul-14 4:07 
QuestionTHANK YOU SOOOOO MUCH! Pin
smithmrk25-Apr-14 10:56
smithmrk25-Apr-14 10:56 
QuestionColour..? Pin
The.Z21-Mar-11 8:48
The.Z21-Mar-11 8:48 
AnswerRe: Colour..? Pin
ondergulsevdi10-Sep-17 4:46
ondergulsevdi10-Sep-17 4:46 
GeneralSo cool, thank you. Pin
Plattler17-Nov-10 11:49
Plattler17-Nov-10 11:49 
GeneralI needed the bitonal conversion method - THANKS! Pin
sklett5-Nov-10 19:20
sklett5-Nov-10 19:20 
I was having a hard time saving 32bpp images to CCITT4 and then realized I needed them to be bitonal. That in turn let me to this article and your conversion method. It works great and it's fast, thanks! Smile | :)
GeneralOut of memory. Error in saving as multipage Pin
libra_Dinesh17-May-10 20:15
libra_Dinesh17-May-10 20:15 
GeneralRe: Out of memory. Error in saving as multipage Pin
raizen24911-Jun-10 9:32
raizen24911-Jun-10 9:32 
GeneralRe: Out of memory. Error in saving as multipage Pin
rsenthilr16-Oct-17 21:55
rsenthilr16-Oct-17 21:55 
GeneralDithering Pin
legerj44637-Apr-10 3:39
legerj44637-Apr-10 3:39 
GeneralThank you! Pin
iperetsman16-Feb-10 2:34
iperetsman16-Feb-10 2:34 
GeneralNeed help. Pin
PankajRai.Net8-Oct-09 2:54
PankajRai.Net8-Oct-09 2:54 
GeneralNeed Your suggestion Pin
Game-point30-Sep-09 19:42
Game-point30-Sep-09 19:42 
GeneralSpecific DPI Pin
nKognito14-Apr-09 23:33
nKognito14-Apr-09 23:33 
GeneralRe: Specific DPI Pin
daelin24-Apr-09 13:32
daelin24-Apr-09 13:32 
GeneralRe: Specific DPI Pin
sklett5-Nov-10 19:22
sklett5-Nov-10 19:22 
QuestionWhat about ColoR????????? help me please Pin
AP0824-Feb-09 23:58
AP0824-Feb-09 23:58 

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.