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

ОБНОВЛЕНИЕ

1 прикрепление - ожидаемый результат
2 приложение - текущий результат expect resultcurrent result

13
задан Jeff Ogata 6 November 2010 в 18:30
поделиться