Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place watermark image on other images (C#, ASP.Net)

Tags:

People also ask

How can I add a watermark to multiple photos online?

Add your watermarkSelect an image from the carousel to set it as backgroun. Then, click "add media" to upload your logo or watermark, or click "add text" to overlay a copyright, author, or url. Adjust the canvas size, and click on a picture in the carousel to preview the result using another photo background.

How do I add a watermark to a PNG file?

❓ How can I add a watermark on PNG image? First, you need to add a PNG image file: drag & drop your PNG image file or click inside the white area to choose a file. Then input watermark text, color, output image format, and click the "Add watermark" button. After the process completes, you can download your result file.

How do I put a watermark on my photos without losing quality?

To do this in Photoshop, go to Image > Resize > Canvas Size, and add the required white space. Then use the Text tool to add your details, or simply paste in your logo. Try to use small or muted writing to avoid a distracting burst of contrast at the fringe of your photo.


How do I add a watermark image onto other images?

I'm able to place text on an image as a water mark but now I have an image that I'd like to put on there instead of the text. How do I do this in C#?

Just one more time to be specific, I have image X and I want to use it as a watermark symbol. I want this symbol to appear on all my image when shown on my website. So I will have image X watermarked on image Y and Z.

Here's the code I currently have that creates the watermark:

public static void AddWaterMark(MemoryStream ms, string watermarkText, MemoryStream outputStream)
        {
            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
            Graphics gr = Graphics.FromImage(img);
            Font font = new Font("Tahoma", (float)40);
            Color color = Color.FromArgb(50, 241, 235, 105);
            double tangent = (double)img.Height / (double)img.Width;
            double angle = Math.Atan(tangent) * (180 / Math.PI);
            double halfHypotenuse = Math.Sqrt((img.Height * img.Height) + (img.Width * img.Width)) / 2;
            double sin, cos, opp1, adj1, opp2, adj2;

            for (int i = 100; i > 0; i--)
            {
                font = new Font("Tahoma", i, FontStyle.Bold);
                SizeF sizef = gr.MeasureString(watermarkText, font, int.MaxValue);

                sin = Math.Sin(angle * (Math.PI / 180));
                cos = Math.Cos(angle * (Math.PI / 180));
                opp1 = sin * sizef.Width;
                adj1 = cos * sizef.Height;
                opp2 = sin * sizef.Height;
                adj2 = cos * sizef.Width;

                if (opp1 + adj1 < img.Height && opp2 + adj2 < img.Width)
                    break;
                //
            }

            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            gr.SmoothingMode = SmoothingMode.AntiAlias;
            gr.RotateTransform((float)angle);
            gr.DrawString(watermarkText, font, new SolidBrush(color), new Point((int)halfHypotenuse, 0), stringFormat);

            img.Save(outputStream, ImageFormat.Jpeg);
        }