المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Text blurring using Graphics.Drawstring



C# Programming
10-22-2009, 11:30 PM
I'm writing strings at a pre-determined ******** to a bitmap.
Though, it seems that if the ******** isn't "snapped to the grid", blurring occurs.
Simple example:

public Bitmap WriteToBitmap(Bitmap bitmapToWriteTo, float X_Pos, float Y_Pos)
{
Graphics g = Graphics.FromImage(bitmapToWriteTo);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;

g.DrawString(this.text, this.font, new SolidBrush(Color.Black), X_Pos, Y_Pos, this.stringFormat);

return bitmapToWriteTo;
}


Nothing else is being done to the bitmap object or any of the other objects involved.
So you may consider the code above as being used as is.
The problem is, however, that using it like this, causes blurring in the text when drawn.
There is a solution to stop the blurring and that is by changing the TextRenderingHint:

g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

Now, this causes the text being drawn to be "snapped to a grid".
However, this messes up my positioning, making it look chaotic.

My question is this, how can I get the result of TextRenderingHint.AntiAliasGridFit, without losing the positioning.
And, to what "grid" is the text being snapped to and am I able to manipulate it ?