locked
Display text as image in c#.net RRS feed

  • Question

  • User-1949221332 posted

    Hi All,

    I want to display text as image using c#.net. And i am using following code.

     int nWidth = 50, nHeight = 30;
                GDI.Pen redPen = new GDI.Pen(GDI.Color.Red, 2);
                GDI.Bitmap b1 = new GDI.Bitmap(nWidth, nHeight);
    
                GDI.Graphics g1 = GDI.Graphics.FromImage(b1);
    
                //String drawString = "طرف";
                
                // Create font and brush.
                GDI.Font drawFont = new GDI.Font("Nafees Nastaleeq(Updated)", 8f,GDI.FontStyle.Regular);
                //GDI.Font drawFont = new GDI.Font("Times New Roman", 9);
                GDI.SolidBrush drawBrush = new GDI.SolidBrush(GDI.Color.Black);
                            
                // Create point for upper-left corner of drawing.
                float x = 25;
                float y = 5;
                // Set format of string.
                GDI.StringFormat drawFormat = new GDI.StringFormat();
                //drawFormat.FormatFlags = GDI.StringFormatFlags.direction;
                //drawFormat.Alignment = System.Drawing.StringAlignment.Center;
                // Draw string to screen.
                //e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                g1.Clear(GDI.Color.White);
                //g1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                g1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
    
                g1.DrawString("Hello", drawFont, drawBrush, x, y, drawFormat);
                
                g1.Flush();


     

    It is working correctly but issue with me is that when it convert text in image, the text did not displayed correctly. so is there any solution that to get the quality result.

    Best Regards,

    Ali bin zubair

     

     

     

     

    Thursday, August 27, 2009 12:50 AM

All replies