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

发布于 2024-09-05 20:02:33 字数 56 浏览 10 评论 0原文

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

I have a strong amount of pictures, which i would like to "protect" by adding watermark on them. Is there any way of adding watermark by using vb.net or C# ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沒落の蓅哖 2024-09-12 20:02:33
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);
}
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);
}
沫雨熙 2024-09-12 20:02:33

这篇博文承诺:

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

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

This blog post promises:

This article shall describe an approach to building a simple watermarking utility that may be used to add watermarks to any supported image file format. The resulting application shall permit the user to open any supported image file format into a scrollable picture box, to define the text to be applied as a watermark (with a default version supplied), to set the font and color of the watermark, to define the opacity of the watermark, to determine whether or not the watermark appears at the top or bottom of the image, and to preview the watermark prior to saving it to the image.

It should provide a good starting point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文