Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以在一系列图片上添加水印吗?_C#_Vb.net_Image Processing_Jpeg_Watermark - Fatal编程技术网

C# 我可以在一系列图片上添加水印吗?

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

我有大量的图片,我想通过添加水印来“保护”它们。有没有办法使用vb.net或C#添加水印?

承诺:

本文将描述一种构建简单水印实用程序的方法,该实用程序可用于向任何支持的图像文件格式添加水印。生成的应用程序应允许用户将任何支持的图像文件格式打开到可滚动的图片框中,定义要应用为水印的文本(提供默认版本),设置水印的字体和颜色,定义水印的不透明度,确定水印是否显示在图像的顶部或底部,并在将水印保存到图像之前预览水印

它应该提供一个良好的起点。

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);
}