1
Answer

Text on image - watermark - font size

Alex Brown

Alex Brown

16y
11.6k
1

I have images, that are stored in sql server.
One of the images is retrieved, into a memory stream, then returned as an Image object.

I then have a method called addWatermark(string text, Image img)

Graphics g = Graphics.FromImage(image);

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawString(text, new Font("Tahoma",fontSize), Brushes.White, new PointF(0, 0));

i want the text to take up around 70% of the width of the image... im trying to calculate the value fontSize (in pink in the code above)

the image thats passed in could be any size.... not always the same size.

Basically, i need to calculate the  max font size, then reduce it by 30% i guess.

any ideas?

Answers (1)