var fd = new FrameDimension(image.FrameDimensionsList[0]);
for (int i = 2; i < image.GetFrameCount(fd); i+=2)
{
using (MemoryStream oMemoryStream = new MemoryStream())
using (MemoryStream oMemoryStream2 = new MemoryStream())
{
image.SelectActiveFrame(fd, i);
image.Save(oMemoryStream, ImageFormat.Tiff);
System.Drawing.Image tiff = System.Drawing.Image.FromStream(oMemoryStream);
Encoder encoder = Encoder.SaveFlag;
ImageCodecInfo encoderInfo = ImageCodecInfo.GetImageEncoders().First(a => a.MimeType == "image/tiff");
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
tiff.Save(oMemoryStream2, encoderInfo, encoderParameters);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
image.SelectActiveFrame(fd, i+1);
image.Save(oMemoryStream, ImageFormat.Tiff);
System.Drawing.Image tiff2 = System.Drawing.Image.FromStream(oMemoryStream);
tiff.SaveAdd(tiff2, encoderParameters);
encoderParameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
tiff.SaveAdd(encoderParameters); // 此時 oMemoryStream2 即為合併的圖檔
}
}
沒有留言:
張貼留言