0

I am adding one watermark image inside the image which user upload in asp.net web application.

I used below code to add watermark image inside uploaded one:

using (Image image = Image.FromFile("Uploaded image path"))
using (Image watermarkImage = Image.FromFile(Server.MapPath(Url.Content("watermark image path")))
using (Graphics imageGraphics = Graphics.FromImage(image))
using (Brush watermarkBrush = new TextureBrush(watermarkImage))
{
    imageGraphics.FillRectangle(watermarkBrush, new Rectangle(6, 10, ((image.Width - ((int)watermarkImage.Width)+80)), ((image.Height - ((int)watermarkImage.Height)+50))));
    image.Save(Server.MapPath(Url.Content("PathToSave/Desert_watermark.jpg")));
}

After save image with watermark when open this image inside folder, I could see watermark image is repeating and size is very small.

Below is the image for the same:

WaterMarkImage

I tried to set Rectangle position, But not able to fix this issue.
Please suggest.

Jimi
  • 29,621
  • 8
  • 43
  • 61
V.Prasad
  • 131
  • 4
  • 19
  • Use the Constructor of the TextureBrush that accepts an Image, a Rectangle and a [WrapMode](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.wrapmode) switch. The default is `WrapMode.Tile`. You probably don't like it. + Specify an area that is the same Size as the Watermark or a source rectangle and a destination rectangle to resize the source Image. – Jimi Apr 11 '21 at 13:54
  • Btw, try this out (not TextureBrush configurable alternative): [Resizing a Bitmap used as watermark the result shows dark borders](https://stackoverflow.com/a/61977870/7444103) – Jimi Apr 11 '21 at 14:27
  • Hello Jimi, Thank you so much for the suggestion, Provided second link Resizing a Bitmap where you have suggested a fabulous approach based on image size, Is what i was looking for. I just tried it and found it is matching with my expectation. Kindly provide your comment as answer so that i could mark it as helpful and do upvote. – V.Prasad Apr 14 '21 at 09:12
  • Sorry, I cannot post an answer that is a link to (or just a copy of) another (even if it's mine). If that answer was useful to you and solved the problem, you can upvote it. I'll set the redirection. – Jimi Apr 14 '21 at 10:30
  • 1
    Ok Jimi, thank you, Will do the same. – V.Prasad Apr 15 '21 at 09:00

0 Answers0