I'm trying to generate a multipage tiff file from an existing picture using following code: (according to this link:http://www.bobpowell.net/generating_multipage_tiffs.htm)
picture.SelectActiveFrame(FrameDimension.Page, 0);
var image = new Bitmap(picture);
using (var stream = new MemoryStream())
{
ImageCodecInfo codecInfo = null;
foreach (var imageEncoder in ImageCodecInfo.GetImageEncoders())
{
if (imageEncoder.MimeType != "image/tiff") continue;
codecInfo = imageEncoder;
break;
}
var parameters = new EncoderParameters
{Param= new []{new EncoderParameter(Encoder.SaveFlag, (long) EncoderValue.MultiFrame)}};
image.Save(stream, codecInfo, parameters);
parameters = new EncoderParameters
{
Param =
new[]
{
new EncoderParameter(Encoder.SaveFlag,
(long) EncoderValue.FrameDimensionPage)
}
};
for (var i = 1; i < picture.GetFrameCount(FrameDimension.Page); i++)
{
picture.SelectActiveFrame(FrameDimension.Page, i);
var img = new Bitmap(picture);
image.SaveAdd(img, parameters);
}
parameters = new EncoderParameters { Param = new[] { new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush) } };
image.SaveAdd(parameters);
stream.Flush();
}
But it's not working and I don't know why .(Only the first frame is included in the image)
What I want to do is to change a particular frame of a tiff file.(adding annotations to it) I don't know if there's a simpler way to do it but what I have in mind is to create a multipage tiff from the original picture and add my own picture instead of that frame.