我正在尝试为多页tiff图像设置元数据。以下是单页tiff图像的代码段设置元数据。
Bitmap imageSource = img as Bitmap; // img is an original singlepage tiff image
Bitmap tempBitmap = new Bitmap(imageSource.Width, imageSource.Height);
try
{
ImageCodecInfo encoderInfo = GetEncoderInfo("image/tiff");
EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT3);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag,(long)EncoderValue.Flush);
encoderParams.Param[1] = parameter;
//Set the resolution as of the image file
tempBitmap.SetResolution(imageSource.HorizontalResolution, imageSource.VerticalResolution);
using (Graphics graphics = Graphics.FromImage(tempBitmap))
{
//Draw the image in the Empty bitmap by passing original imageSource
graphics.DrawImage(imageSource, 0, 0, (float)imageSource.Width, (float)imageSource.Height);
}
string strSign = "I am author";
PropertyItem propItem = img.PropertyItems[0];
propItem.Id = 315; // this is called 'Author'
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes(strSign + "\0");//signature;
propItem.Len = propItem.Value.Length;
((Image)tempBitmap).SetPropertyItem(propItem);
img.Dispose();
((Image)tempBitmap).Save("sample.tif", encoderInfo, encoderParams);
}
catch (Exception ex)
{
}
以上代码适用于单页图像,但无法实现多页图像的设置元数据。我对此有点新鲜,任何可用于实现多页tiff图像设置元数据的有用链接或库都会有所帮助。