I need to convert text to image, using specified fonts, size, etc. Looks like everything is ok when using standard DrawString method but, when I'm trying to do it under Windows 7 I have my picture blurred.
this is a screenshot from Windows XP / Windows 2008 server
http://testmyblog.ho.ua/pictures/xp.png
and this is from Windows 7
http://testmyblog.ho.ua/pictures/7.png
Also I tried to play with System.Drawing.Imaging.Encoder.Quality;
but even with max value of EncoderParameter blur effect doesn't disappear.
I have no idea where is the problem, hope that you will be able to help.
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Nov 20, 2009, 4:52 PM EST
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush b = new SolidBrush(Color.Black);
//this is to Draw Antialiaced Clean String
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.DrawString("Kirtan", new Font(FontFamily.GenericSansSerif, 50), b, new Point(200, 50));
}
Oleg8 reputationPosted Nov 24, 2009, 9:58 PM EST
I tried this solution, but it only removes colored pixels from picture, blur effect doesn't disappear. The important point that I need to use font size from 5 to 20.
Here is a picture with size 7:
http://img214.imageshack.us/img214/4670/fromfile.png
I tried to draw text in the pictureBox (probably the problem was in exporting to the file or something) but the picture looks the same as in file.
http://img214.imageshack.us/img214/9834/fromform.png
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 24, 2009, 10:13 PM EST
The Drawing you are Talking about is Vector Drawing. basically Antialiase Feature can make Drawing smoother than it looks
so when you zoom your image in windows form with button actually yo need to redraw it so use fills that image quality is not
reduced after zooming :)
Lalit MRank #1,186 · 1.5K reputationPosted Nov 24, 2009, 10:17 PM EST
you can try this code for Convert text to image in c# using System.Drawing namespace.
Here we create a bitmap image and use its Graphics property to convert text passed to image and place the image in a picture box.
private void TextToImage() { Color BackColor = Color.White; String FontName = "Times New Roman"; int FontSize = 25; int Height = 50; int Width = 300; span style="color: rgb(56, 118, 29);"> //creating bitmap image span style="color: rgb(0, 0, 0);">Bitmap span>span>bitmap = new Bitmap(Width, Height); span style="color: rgb(56, 118, 29);">//FromImage method creates a new Graphics from the specified Image. Graphics graphics = Graphics.FromImage(bitmap); Color color = Color.Gray; Font font = new Font(FontName, FontSize); SolidBrush BrushBackColor = new SolidBrush(BackColor); Pen BorderPen = new Pen(color); Rectangle displayRectangle = new Rectangle(new Point(0, 0), new Size(Width - 1, Height - 1)); span style="color: rgb(56, 118, 29);">//Drawing a rectangle and filling the background as white span style="color: rgb(0, 0, 0);">graphicsspan>span>.FillRectangle(BrushBackColor, displayRectangle); graphics.DrawRectangle(BorderPen, displayRectangle); span style="color: rgb(56, 118, 29);"> //giving the font and color to the string passed graphics.DrawString(txtEnter.Text,font,Brushes.Red, 0, 0); pictureBox1.Image = bitmap; }