By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

merge images

P: n/a
hi,everyone
I have a question about merging images. I want to merge serval tiff
images into one file using C#,that means the final file has multiple
frames.My problem is that I want each frame in the final file is of
single-strip,but when I want to merge serval images which has been of
singe-strip,the final file my codes produced contains images which are all
of multiple-strips. My codes is listed below:

public static bool MergeTifs(ref string mergedFile,ArrayList
fileList)
{
int counts = fileList.Count;
if (counts < 1)
{
return false;
}
try
{
EncoderParameters eps=new EncoderParameters(2);

eps.Param[0] = new

EncoderParameter(Encoder.SaveFlag,(long)EncoderVal ue.MultiFrame);
eps.Param[1] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT3);

System.Drawing.Image mergedImage =
System.Drawing.Image.FromFile((string)fileList[0]);

//Get the correct encoder from the list of available
encoders

ImageCodecInfo[] infos = ImageCodecInfo.GetImageEncoders();

int n=0;
while(infos[n].MimeType!="image/tiff")
n++;

//save the first page
System.Drawing.Image imageToAdd = null;
mergedImage.Save(mergedFile,infos[n],eps);
Bitmap firstBmp = new Bitmap((string)fileList[0]);
int first_num = firstBmp.GetFrameCount(FrameDimension.Page);
for(int j = 1; j < first_num; j++)
{
firstBmp.SelectActiveFrame(FrameDimension.Page,j);
eps.Param[0]=new
EncoderParameter(Encoder.SaveFlag,(long)EncoderVal ue.FrameDimensionPage);
mergedImage.SaveAdd(firstBmp,eps);
}
firstBmp.Dispose();
for(int i = 1; i< counts; i++)
{
string fileToAdd = (string)fileList[i];
imageToAdd = System.Drawing.Image.FromFile(fileToAdd);
int num =
imageToAdd.GetFrameCount(FrameDimension.Page);
for(int k = 0; k < num; k++)
{

imageToAdd.SelectActiveFrame(FrameDimension.Page,k );
eps.Param[0]=new
EncoderParameter(Encoder.SaveFlag,(long)EncoderVal ue.FrameDimensionPage);
mergedImage.SaveAdd(imageToAdd,eps);
}
imageToAdd.Dispose();
}
eps.Param[0]=new

EncoderParameter(Encoder.SaveFlag,(long)EncoderVal ue.Flush);
mergedImage.SaveAdd(eps);
mergedImage.Dispose();
return true;
}
catch
{
return false;
}
}

the first parameter is the file name of the final file.
Could anyone kindly help me? Thank you in advance.

Crespo

2006-07-03
Jul 4 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.