How can the font size and the position of the watermark text in an image based on image size set?
I'm looking for a solution to alter the font size according to the image size.
also Transparent watermark.
my function:
public void fn_TextWaterMark(string text,ImageFormat fmt)
{
string sourceImage = "c:\\a.jpg;
string targetImage = "c:\\a-watermark.jpg;
try
{
//open source image as stream and create a memorystream for output
FileStream source = new FileStream(sourceImage, FileMode.Open);
Stream output = new MemoryStream();
Image img = Image.FromStream(source);
//choose font for text
Font font = new Font("Times New Roman", 20, FontStyle.Bold, GraphicsUnit.Pixel);
//choose color and transparency
Color color = Color.FromArgb(255, 255, 255, 255);
//location of the watermark text in the parent image
default//Point pt = new Point(100, 100);
Point pt = new Point(img.Width*31/100, img.Height*46/100);
SolidBrush brush = new SolidBrush(color);
//draw text on image
Graphics graphics = Graphics.FromImage(img);
graphics.DrawString(text, font, brush, pt);
graphics.Dispose();
//update image memorystream
img.Save(output, fmt);
Image imgFinal = Image.FromStream(output);
//write modified image to file
Bitmap bmp = new System.Drawing.Bitmap(img.Width,img.Height, img.PixelFormat);
Graphics graphics2 = Graphics.FromImage(bmp);
graphics2.DrawImage(imgFinal, new Point(0,0));
bmp.Save(targetImage, fmt);
imgFinal.Dispose();
img.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
pic examp:
https://i.stack.imgur.com/ZShUI.jpg
https://i.stack.imgur.com/GUfbM.jpg
thanks