views:

71

answers:

3

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# ?

A: 

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.

ChrisF
A: 

Use ImageMagick with the .Net wrapper.

Serapth
+1  A: 
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);
}
Glennular