C# 我可以在一系列图片上添加水印吗?
我有大量的图片,我想通过添加水印来“保护”它们。有没有办法使用vb.net或C#添加水印?承诺: 本文将描述一种构建简单水印实用程序的方法,该实用程序可用于向任何支持的图像文件格式添加水印。生成的应用程序应允许用户将任何支持的图像文件格式打开到可滚动的图片框中,定义要应用为水印的文本(提供默认版本),设置水印的字体和颜色,定义水印的不透明度,确定水印是否显示在图像的顶部或底部,并在将水印保存到图像之前预览水印 它应该提供一个良好的起点。与C# 我可以在一系列图片上添加水印吗?,c#,vb.net,image-processing,jpeg,watermark,C#,Vb.net,Image Processing,Jpeg,Watermark,我有大量的图片,我想通过添加水印来“保护”它们。有没有办法使用vb.net或C#添加水印?承诺: 本文将描述一种构建简单水印实用程序的方法,该实用程序可用于向任何支持的图像文件格式添加水印。生成的应用程序应允许用户将任何支持的图像文件格式打开到可滚动的图片框中,定义要应用为水印的文本(提供默认版本),设置水印的字体和颜色,定义水印的不透明度,确定水印是否显示在图像的顶部或底部,并在将水印保存到图像之前预览水印 它应该提供一个良好的起点。与 public void AddWatermark(str
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);
}