10 Mart 2015

Belirlediğiniz ölçü, renk, font ve zemin renginde resim çıktısı üretebileceğiniz ve metin girebileceğiniz kod:

public static void DrawText(string text, Font font, Color textColor, Color backColor)
{
 Image img = new Bitmap(1, 1);
 Graphics drawing = Graphics.FromImage(img);
 SizeF textSize = drawing.MeasureString(text, font);

 img.Dispose();
 drawing.Dispose();

 img = new Bitmap((int)textSize.Width, (int)textSize.Height);

 drawing = Graphics.FromImage(img);

 drawing.Clear(backColor);

 Brush textBrush = new SolidBrush(textColor);

 drawing.DrawString(text, font, textBrush, 0, 0);

 drawing.Save();

 textBrush.Dispose();
 drawing.Dispose();

 img.Save("filename", ImageFormat.Jpeg);
 img.Dispose();
}

Tagged: ,

0 yorum:

Yorum Gönder