Je veux rendre du texte en tant qu'image dans ASP.NET. Cela fonctionne bien, mais le texte est rendu très moche (avec des pixels gris autour du texte) même si j'active AntiAlias (ou ClearType) en changeant l'option graphique TextRenderingHint.Rendu laid d'image avec DrawString-Method (ASP.NET)
Voici le code correspondant:
float width;
float height;
System.Drawing.Text.PrivateFontCollection fontcollection = new System.Drawing.Text.PrivateFontCollection();
// Add the custom font families
fontcollection.AddFontFile(Server.MapPath("./Fonts/" + fontfile));
Bitmap image = new Bitmap(10, 10);
Graphics graphic = Graphics.FromImage(image);
Font font = new Font(fontcollection.Families.First(), fontsize, style);
SizeF size = graphic.MeasureString(text, font);
width = size.Width;
height = size.Height;
image = new Bitmap(Convert.ToInt32(width), Convert.ToInt32(height));
graphic = Graphics.FromImage(image);
graphic.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
graphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphic.DrawString(text, font, Brushes.Black, new PointF(0, 0));
Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Voici un lien vers l'image générée (zoom):
l'image zoomée:
Comment puis-je résoudre ça?
Fournissez une image non agrandie s'il vous plaît. – leppie
Lien vers l'image non agrandie: http://i.imgur.com/Ymkrl.jpg –