Convert bitmaps to one multipage TIFF image in .NET 2.0

后端 未结 7 1975
有刺的猬
有刺的猬 2020-11-27 11:29

How can i convert an array of bitmaps into a brand new image of TIFF format, adding all the bitmaps as frames in this new tiff image?

using .NET 2.0.

7条回答
  •  难免孤独
    2020-11-27 12:01

    Came across this post after a bit of searching on Google. I tried the code that was in the post by a'b'c'd'e'f'g'h', but that didn't work for me. Perhaps, I was not doing something correctly.

    In any case, I found another post that saved images to multi page tiffs. Here is the link to the post: http://www.bobpowell.net/addframes.htm

    Also, here is the code that worked for me. It should be identical to that post.

    Encoder encoder = Encoder.SaveFlag;
    ImageCodecInfo encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == "image/tiff");
    EncoderParameters encoderParameters = new EncoderParameters(1);
    encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
    
    // Save the first frame of the multi page tiff
    Bitmap firstImage = (Bitmap) _scannedPages[0].RawContent;
    firstImage.Save(fileName, encoderInfo, encoderParameters);
    
    encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
    
    // Add the remaining images to the tiff
    for (int i = 1; i < _scannedPages.Count; i++)
    {
       Bitmap img = (Bitmap) _scannedPages[i].RawContent;
       firstImage.SaveAdd(img, encoderParameters);
    }
    
    // Close out the file
    encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
    firstImage.SaveAdd(encoderParameters);
    

提交回复
热议问题