winforms – C# – 通过特殊的方式将水印添加到照片中

我需要通过特殊的方式为照片添加水印.我知道如何做,但我不知道如何做到与第 http://www.photoshopessentials.com/photo-effects/copyright/条相同的方式

这里是添加水印的方法.我可以如何改变它以获得水印图像,如上面的文章

public static Bitmap AddWatermark(this Bitmap originalImage,Bitmap watermarkImage,WatermarkLocationEnum location)
{
    int offsetWidth;
    int offsetHeight;
    if ((watermarkImage.Width > originalImage.Width) | (watermarkImage.Height > originalImage.Height))
        throw new Exception("The watermark must be smaller than the original image.");
    Bitmap backgroundImage = new Bitmap((Bitmap)originalImage.Clone());
    Bitmap image = new Bitmap(backgroundImage.Width,backgroundImage.Height);
    Graphics graphics = Graphics.FromImage(image);
    offsetWidth = GetoffsetWidth(image.Width,watermarkImage.Width,location);
    offsetHeight = GetoffsetHeight(image.Height,watermarkImage.Height,location);
    watermarkImage.SetResolution(backgroundImage.HorizontalResolution,backgroundImage.VerticalResolution);
    offsetWidth = Math.Max(offsetWidth - 1,0);
    offsetHeight = Math.Max(offsetHeight - 1,0);
    graphics.DrawImage(watermarkImage,offsetWidth,offsetHeight);
    for (int i = offsetWidth; i < (offsetWidth + watermarkImage.Width); i++)
    {
        for (int j = offsetHeight; j < (offsetHeight + watermarkImage.Height); j++)
        {
            Color pixel = image.GetPixel(i,j);
            if (pixel.A > 0)
            {
                Color color = Color.FromArgb(pixel.A,pixel.R,pixel.G,pixel.B);
                Color imagePixelColor = backgroundImage.GetPixel(i,j);
                double alpha = (double)color.A / 255;
                Color newColor = Color.FromArgb(255,(int)((double)imagePixelColor.R * (1.0 - alpha) + alpha * color.R),(int)((double)imagePixelColor.G * (1.0 - alpha) + alpha * color.G),(int)((double)imagePixelColor.B * (1.0 - alpha) + alpha * color.B));
                backgroundImage.SetPixel(i,j,newColor);
            }
        }
    }
    return backgroundImage;
}

//............
Image img = Bitmap.FromFile("DSC00766.JPG");
var wtm = (Bitmap)Bitmap.FromFile("copyright1.jpg");
((Bitmap)img).AddWatermark(wtm,WatermarkLocationEnum.BottomCenter).Save("new.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

UPDATE

1附加结果
2附件结果

解决方法

如果您创建您的版权图像,使其是半透明的并且具有这样的透明背景(使用Paint.NET):

您可以从中创建一个TextureBrush,并使用它来绘制原始图像的版权:

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

这产生了这个结果:

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...