Last post Nov 06, 2007 05:59 PM by vvhagen
Oct 21, 2007 02:47 PM|psdcode|LINK
I have graphics object .. and i want to draw a simple string on it ... !!! using this code:
grp.DrawString(myText, myFont, mySolidBrush, myDrawPoint, StringFormat.GenericDefault);
However .. i noticed that my string (size=12) is not clear at all and the resolution is very low .. !!! but .. when i change the font (new Font(fontFamily, 40)) to something like 40 .. the resolution becomes little bit better .. !!!
Can someone guide me on How can i get a small & high resolution texts on images ?!?!
I tried grp.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit ... but the font is still not clear .. !!!
is ClearTypeGridFit the best option ?!
Do you have any suggestions/advice ?
Thanks for help.
Oct 22, 2007 01:54 PM|SGWellens|LINK
Is it possible that you are drawing on a very large (or small) image? If the image is then scaled for viewing, it may make the text look bad. Does the resolution look OK when viewed at full size?
Oct 25, 2007 11:48 AM|psdcode|LINK
Thaank you for reply .. & Sorry .. for my late visit.
i created a Graphics instance ..:
myGraphics = Graphics.FromImage(new Bitmap(100,100));
then i get the width & height ...
int Width = (int)DrawGraphics.MeasureString(text, myFont).Width;
int Height = (int)DrawGraphics.MeasureString(text, myFont).Height;
Then i create another Bitmap object .. that has those Width & Height Sizes:
myBitmap = new Bitmap(Width, Height); ...
myGraphics = Graphics.FromImage(myBitmap);
and i draw my string on myGraphics object !.
What can be the cause of the bad resolution ? or how can i improve the resolution ? or .. can you give me an example that produce high resolution text image .. please make the text equal to "16px".. if you have.
again .. thanks for help and reply ... and i'll be waiting for you SGWellens.
Oct 26, 2007 07:23 AM|psdcode|LINK
Oct 30, 2007 11:42 AM|WoogyChuck|LINK
I'm having the same issues. As the font get's smaller, it appears to get bolder and the kerning is reduced creating unreadable blobs.
Here's an example:
Oct 30, 2007 05:13 PM|Avarice|LINK
I have this issue as well. Anything under a 16pt font appears unreadable.
Oct 30, 2007 08:48 PM|SGWellens|LINK
I dug out a function I wrote a while ago...it seems to work fine. I tried saving both as a bitmap and jpeg to see if there was a quality difference.
protected void Button1_Click(object sender, EventArgs e)
MyBitmap = TextToBitmap("Hello World");
public static Bitmap TextToBitmap(String TheText)
Font DrawFont = null;
SolidBrush DrawBrush = null;
Graphics DrawGraphics = null;
Bitmap TextBitmap = null;
// start with empty bitmap, get it's graphic's object
// and choose a font
TextBitmap = new Bitmap(1, 1);
DrawGraphics = Graphics.FromImage(TextBitmap);
DrawFont = new Font("Arial", 14);
// see how big the text will be
int Width = (int)DrawGraphics.MeasureString(TheText, DrawFont).Width;
int Height = (int)DrawGraphics.MeasureString(TheText, DrawFont).Height;
// recreate the bitmap and graphic object with the new size
TextBitmap = new Bitmap(TextBitmap, Width, Height);
DrawGraphics = Graphics.FromImage(TextBitmap);
// get the drawing brush and where we're going to draw
DrawBrush = new SolidBrush(Color.Black);
PointF DrawPoint = new PointF(0, 0);
// clear the graphic white and draw the string
DrawGraphics.DrawString(TheText, DrawFont, DrawBrush, DrawPoint);
// don't dispose the bitmap, the caller needs it.
Oct 31, 2007 10:36 AM|WoogyChuck|LINK
I noticed that your code had 2 differences to my code.
So here's what I think is happening. If you don't use the Clear statement with a PNG, it still renders OK because the background is transparent. However, the background used for anti-aliasing the text is still black, just like a jpeg in GDI. If you use the
Clear statement using white the text will anti-alias correctly.
Unfortunately, painting the background a solid color eleminates the alpha-transparency of the png making it pointless.
Does anybody know of a way to change the matte color used for the anti-aliasing without actually painting the image with a color?
Nov 06, 2007 05:59 PM|vvhagen|LINK
It all depends on the font, colors, size, etc. you want to use in your image. Unfortunately there's no golden rule for what option to use in which scenario (welll, at least I didn't discover it yet).
I had the same type of issues you're encountering, but each type of image needed a different way of tweaking the to get the maximum result. From what I experienced these are the properties that varied in every solution in descending order of impact on the
1) TextRenderingHint, 2) SmoothingMode, 3) TextContrast, 4) PixelOffsetMode, 5) ComposingQuality and 6) InterpolationMode.
To test it I created a little tool that generates a table full of images varying by two parameters (put on the x- and y-axis) at the time and then I just picked the best result, I used those options and recreated the table of images again using some other
Hope it helps.