我正在尝试打开 TIFF 图像,添加水印并将其保存回完全相同的 TIFF 格式。我的代码适用于 PNG,但无法打开和操作 TIFF 文件。我尝试使用TiffBitmapDecoder但我无法让它工作。我已经工作了 16 个小时,没有运气。
string fileName = "sample.tiff";
int opacity = 127;
int X, Y;
string text = "My Sample Watermark";
Font font = new Font("Verdana", 18.0f);
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
// I need to do something here to convert the stream so it can used by the Image object.
Image image = Image.FromStream(stream);
Graphics g = Graphics.FromImage(image);
Brush myBrush = new SolidBrush(Color.FromArgb(opacity, Color.SteelBlue));
SizeF sz = g.MeasureString(text, font);
X = (int)(image.Width - sz.Width) / 2;
Y = (int)(image.Height - sz.Height);
g.DrawString(text, font, myBrush, new Point(X, Y));
stream.Dispose();
File.Delete(fileName);
// I need to do something here to save the Image in TIFF format with the same exact characteristics.
image.Save(fileName);
我正在从电影文件中提取原始 TIFF。现在我正在使用“Imagemagick convert CLI”来添加水印,但我想使用 VB C# 或者不必调用命令行来执行此操作。