CSHARP
private void CreateTextToImageFile(string strMsg, string OutputFile, Color clrBackground, Color clrForeground, int fontSize = 12, FontStyle fontStyle = FontStyle.Regular, System.Drawing.Drawing2D.SmoothingMode smoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias, System.Drawing.Text.TextRenderingHint textRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias) { Bitmap objBmpImage = new Bitmap(1, 1); int intWidth = 0; int intHeight = 0; if (fontSize == 0) fontSize = 10; if (OutputFile == "") OutputFile = @"C:\String2Image.jpg"; if (strMsg == "") strMsg = "Message is Nothing"; Font objFont = new Font("Arial", fontSize, fontStyle, GraphicsUnit.Pixel); Graphics objGraphics = Graphics.FromImage(objBmpImage); intWidth = (int)objGraphics.MeasureString(strMsg, objFont).Width; intHeight = (int)objGraphics.MeasureString(strMsg, objFont).Height; objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight)); objGraphics = Graphics.FromImage(objBmpImage); objGraphics.Clear(clrBackground); objGraphics.SmoothingMode = smoothingMode; objGraphics.TextRenderingHint = textRenderingHint; objGraphics.DrawString(strMsg, objFont, new SolidBrush(clrForeground), 0, 0); objGraphics.Flush(); objBmpImage.Save(OutputFile); }