我有大量图片,我想通过在它们上添加水印来“保护”它们。有没有办法使用 vb.net 或 C# 添加水印?
问问题
1889 次
3 回答
2
public void AddWatermark(string filename, string watermarkText, Stream outputStream) {
Bitmap bitmap = Bitmap.FromFile(filename);
Font font = new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel);
Color color = Color.FromArgb(10, 0, 0, 0); //Adds a black watermark with a low alpha value (almost transparent).
Point atPoint = new Point(100, 100); //The pixel point to draw the watermark at (this example puts it at 100, 100 (x, y)).
SolidBrush brush = new SolidBrush(color);
Graphics graphics = null;
try {
graphics = Graphics.FromImage(bitmap);
} catch {
Bitmap temp = bitmap;
bitmap = new Bitmap(bitmap.Width, bitmap.Height);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(temp, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel);
temp.Dispose();
}
graphics.DrawString(text, font, brush, atPoint);
graphics.Dispose();
bitmap.Save(outputStream);
}
于 2010-06-14T21:40:18.747 回答
1
将 ImageMagick与.Net 包装器一起使用。
于 2010-06-14T21:40:00.163 回答
0
这篇博文承诺:
本文将描述一种构建简单水印实用程序的方法,该实用程序可用于将水印添加到任何受支持的图像文件格式。生成的应用程序应允许用户将任何支持的图像文件格式打开到可滚动的图片框中,定义要应用为水印的文本(提供默认版本),设置水印的字体和颜色,定义水印的不透明度,以确定水印是否出现在图像的顶部或底部,并在将水印保存到图像之前预览水印。
它应该提供一个很好的起点。
于 2010-06-14T21:39:43.393 回答