merge images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zeeway

    merge images

    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,Arra yList
    fileList)
    {
    int counts = fileList.Count;
    if (counts < 1)
    {
    return false;
    }
    try
    {
    EncoderParamete rs eps=new EncoderParamete rs(2);

    eps.Param[0] = new

    EncoderParamete r(Encoder.SaveF lag,(long)Encod erValue.MultiFr ame);
    eps.Param[1] = new EncoderParamete r(Encoder.Compr ession,
    (long)EncoderVa lue.Compression CCITT3);

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

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

    ImageCodecInfo[] infos = ImageCodecInfo. GetImageEncoder s();

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

    //save the first page
    System.Drawing. Image imageToAdd = null;
    mergedImage.Sav e(mergedFile,in fos[n],eps);
    Bitmap firstBmp = new Bitmap((string) fileList[0]);
    int first_num = firstBmp.GetFra meCount(FrameDi mension.Page);
    for(int j = 1; j < first_num; j++)
    {
    firstBmp.Select ActiveFrame(Fra meDimension.Pag e,j);
    eps.Param[0]=new
    EncoderParamete r(Encoder.SaveF lag,(long)Encod erValue.FrameDi mensionPage);
    mergedImage.Sav eAdd(firstBmp,e ps);
    }
    firstBmp.Dispos e();
    for(int i = 1; i< counts; i++)
    {
    string fileToAdd = (string)fileLis t[i];
    imageToAdd = System.Drawing. Image.FromFile( fileToAdd);
    int num =
    imageToAdd.GetF rameCount(Frame Dimension.Page) ;
    for(int k = 0; k < num; k++)
    {

    imageToAdd.Sele ctActiveFrame(F rameDimension.P age,k);
    eps.Param[0]=new
    EncoderParamete r(Encoder.SaveF lag,(long)Encod erValue.FrameDi mensionPage);
    mergedImage.Sav eAdd(imageToAdd ,eps);
    }
    imageToAdd.Disp ose();
    }
    eps.Param[0]=new

    EncoderParamete r(Encoder.SaveF lag,(long)Encod erValue.Flush);
    mergedImage.Sav eAdd(eps);
    mergedImage.Dis pose();
    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-06


Working...