public static void DrawPelakOnImage(Image targetImage,
string textToDraw,
Point textlocation,
Font textFont,
Color textColor,
bool drawBackground,
Color backgroundColor)
{
try
{
if (targetImage is null)
{
return;
}
if (textlocation == Point.Empty)
{
return;
}
if (textFont is null)
{
return;
}
using Graphics graphics = Graphics.FromImage(targetImage);
graphics.PageUnit = GraphicsUnit.Pixel;
// The Backgrounds must be draw first to prevent overlaping.
if (drawBackground)
{
Rectangle rect = new((textlocation.X - 160), (textlocation.Y - 3), 405, 40);
graphics.DrawRectangle(new Pen(backgroundColor), rect);
graphics.FillRectangle(new SolidBrush(backgroundColor), rect);
}
graphics.DrawString(textToDraw, textFont,new SolidBrush(textColor),textlocation);
}
catch
{
throw;
}
}