First render the shadow by drawing the text with a darker, optionally translucent brush with offset. After the shadow is displayed, overlay the plain text.
An example :
public static System.Drawing.Image GenerateGiftCard(String text, Font font, Color textColor, Color shadowColor, SizeF shadowOffset)
{
System.Drawing.Image img = Bitmap.FromFile(@"G:\xxxx\images\gift-card.jpg");
Graphics drawing = Graphics.FromImage(img);
SizeF textSize = drawing.MeasureString(text, font);
Brush shadowBrush = new SolidBrush(shadowColor);
Brush textBrush = new SolidBrush(textColor);
float x, y;
x = img.Width / 2 - textSize.Width / 2;
y = img.Height / 2 - textSize.Height / 2;
drawing.DrawString(text, font, shadowBrush, x + shadowOffset.Width, y + shadowOffset.Height);
drawing.DrawString(text, font, textBrush, x, y);
drawing.Save();
textBrush.Dispose();
drawing.Dispose();
return img;
}
source
share