C# - Add watermark to the photo by special way

前端 未结 1 632
臣服心动
臣服心动 2020-12-13 07:22

I need add watermark to the photo by special way. I know how to do it, but I dunno how to do it the same way as in article http://www.photoshopessentials.com/photo-effects/c

相关标签:
1条回答
  • 2020-12-13 08:07

    If you create your copyright image so that it is translucent and has a transparent background like this (using Paint.NET):

    alt text

    you can create a TextureBrush from it and use that to draw the copyright over the original image:

    private void button2_Click(object sender, EventArgs e)
    {
        using (Image image = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"))
        using (Image watermarkImage = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\watermark.png"))    
        using (Graphics imageGraphics = Graphics.FromImage(image))
        using (Brush watermarkBrush = new TextureBrush(watermarkImage))
        {
            imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(0, 0), image.Size));
            image.Save(@"C:\Users\Public\Pictures\Sample Pictures\Desert_watermark.jpg");
        }
    }
    

    which produces this result:

    alt text

    0 讨论(0)
提交回复
热议问题