Click here to Skip to main content
13,193,816 members (45,477 online)
Click here to Skip to main content
Add your own
alternative version

Stats

324.3K views
15.2K downloads
91 bookmarked
Posted 27 Dec 2006

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

, 27 Dec 2006
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

bijulsoni
Software Developer Microsoft
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralRe: Saving bitonal TIFFs Pin
Dave Willemssen3-Nov-08 11:29
memberDave Willemssen3-Nov-08 11:29 
Generalmultipage tif from *.tif and *.jpg Pin
Member #393399918-Mar-07 5:52
memberMember #393399918-Mar-07 5:52 
GeneralProblem when converting to vb.net 2005 code Pin
STI0617-Mar-07 5:07
memberSTI0617-Mar-07 5:07 
GeneralRe: Problem when converting to vb.net 2005 code Pin
bijulsoni17-Mar-07 6:53
memberbijulsoni17-Mar-07 6:53 
GeneralRe: Problem when converting to vb.net 2005 code Pin
STI0617-Mar-07 10:50
memberSTI0617-Mar-07 10:50 
GeneralRe: Problem when converting to vb.net 2005 code Pin
jo0ls17-Mar-07 15:13
memberjo0ls17-Mar-07 15:13 
GeneralRe: Problem when converting to vb.net 2005 code Pin
STI0618-Mar-07 1:20
memberSTI0618-Mar-07 1:20 
QuestionRe: Problem when converting to vb.net 2005 code Pin
joaopalma16-Jan-13 23:11
memberjoaopalma16-Jan-13 23:11 
The link to vb.net source is unavailable.

Can you help with that?

Tks
QuestionIs there a way to convert PCL to Tiff ? Pin
dibblm-Ohio1-Feb-07 8:39
memberdibblm-Ohio1-Feb-07 8:39 
AnswerRe: Is there a way to convert PCL to Tiff ? Pin
bijulsoni3-Feb-07 9:59
memberbijulsoni3-Feb-07 9:59 
AnswerRe: Is there a way to convert PCL to Tiff ? [modified] Pin
illium6-Jun-07 9:13
memberillium6-Jun-07 9:13 
QuestionBlack And White? Pin
Polymorpher3-Jan-07 16:46
memberPolymorpher3-Jan-07 16:46 
AnswerRe: Black And White? Pin
Michael Loux4-Jan-07 2:30
memberMichael Loux4-Jan-07 2:30 
GeneralRe: Black And White? Pin
Polymorpher4-Jan-07 3:38
memberPolymorpher4-Jan-07 3:38 
QuestionRe: Black And White? Pin
sooge9-May-07 3:40
membersooge9-May-07 3:40 
AnswerRe: Black And White? Pin
Polymorpher9-May-07 8:55
memberPolymorpher9-May-07 8:55 
AnswerRe: Black And White? Pin
Polymorpher9-May-07 19:41
memberPolymorpher9-May-07 19:41 
GeneralRe: Black And White? Pin
sooge9-May-07 21:12
membersooge9-May-07 21:12 
GeneralRe: Black And White? Pin
Polymorpher10-May-07 9:26
memberPolymorpher10-May-07 9:26 
QuestionRe: Black And White? Pin
Member 38792987-Feb-08 6:46
memberMember 38792987-Feb-08 6:46 
QuestionSplitting multi-page tiffs Pin
robrich27-Dec-06 9:59
memberrobrich27-Dec-06 9:59 
AnswerRe: Splitting multi-page tiffs Pin
bijulsoni4-Jan-07 6:46
memberbijulsoni4-Jan-07 6:46 
QuestionRe: Splitting multi-page tiffs Pin
bhupathidotnet8-Apr-07 23:15
memberbhupathidotnet8-Apr-07 23:15 
AnswerRe: Splitting multi-page tiffs Pin
bijulsoni9-Apr-07 21:53
memberbijulsoni9-Apr-07 21: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171018.2 | Last Updated 27 Dec 2006
Article Copyright 2006 by bijulsoni
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid