Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Add watermark to the photo by special way
    primarykey
    data
    text
    <p>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 <a href="http://www.photoshopessentials.com/photo-effects/copyright/" rel="noreferrer">http://www.photoshopessentials.com/photo-effects/copyright/</a></p> <p>Here is method to add watermark. How I can change it to get image with watermark such as in article above?</p> <pre><code>public static Bitmap AddWatermark(this Bitmap originalImage, Bitmap watermarkImage, WatermarkLocationEnum location) { int offsetWidth; int offsetHeight; if ((watermarkImage.Width &gt; originalImage.Width) | (watermarkImage.Height &gt; 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 &lt; (offsetWidth + watermarkImage.Width); i++) { for (int j = offsetHeight; j &lt; (offsetHeight + watermarkImage.Height); j++) { Color pixel = image.GetPixel(i, j); if (pixel.A &gt; 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); </code></pre> <p><strong>UPDATE</strong></p> <p>1 attach- expect result<br> 2 attach- current result <img src="https://i.stack.imgur.com/7HsQT.jpg" alt="expect result"> <img src="https://i.stack.imgur.com/52HV8.jpg" alt="current result"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload