DrawString, 96dpi.....bad quality?

LeonR

Well-known member
Joined
Nov 2, 2006
Messages
139
Location
UK
Programming Experience
10+
I am writing some software which overlays text on to an image.

The code is quite straight forward, I am basically creating a new bitmap obect, then loading a jpg (or bmp) into it , then assigning it to a graphics object (if thats teh correct term), using the drawstring function and outputing it accordingly (PDF, physical printer etc).

The problem is that to get the text to look nice, I have to force the dpi to something around 150 or higher, and that means I have to change my jpegs around (otherwise they print smaller, as they are 96dpi).

Should the text really be blocky and rough looking at 96dpi?

I have tried playing with



VB.NET:
Graphic.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        Graphic.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        Graphic.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
        'Graphic.CompositingMode = Drawing2D.CompositingMode.SourceCop 
        Graphic.InterpolationMode = Drawing2D.InterpolationMode.Bicubic

But im not having much luck.


I can get around the problem by using higher dpi's, but its not ideal as it has a performance impact, and I feel that overlaying some fixed width font on a pretty basic jpeg (lines and boxes) should be pretty simple.

Obviously I could just put up with blocky text, but I want to make it 'nice'.


Any help/ideas appreciated!
 
Graphic.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit This has helped quite a bit at 150dpi. acceptable now. Not solid black though.
 
TextRenderingHint setting is important for quality of drawn text.
jpg (or bmp)
That is a significant difference. Jpg is a compressed image format and will to a degree blur any content. Bmp is not compressed, so saving will not make content worse than when rendered. There is also Png, which they say has lossless compression.

I have not found drawn text to be bad quality on default 96dpi by the way, perhaps it is the font or font size you're using?
 
Hi John, thanks for your input!

It is really bizzare I must admit. I played around with the setting you suggested using various options and they do make a big difference.

In regards to the font used, i'm using courier new (tried courier aswell) as I need a monospace font, due to the way the text has to overlay the image template.

You mention jpg and bmp, I have tried using various formats , aswell as png and it doesn't see, to make any different in regards to the text.

The only thing that makes the text look acceptable is by forcing the dpi up to at least 150 on the bitmap object before I start using drawstring.

I am not saving the image, im printing it directly to a printer, or PDF writer. I did test as saving to jpeg and it had the same quality as the print outs and PDF, so it's not printer setting related it seems.

Think dot matrix, thats what the text looks like in 96dpi :D

I think for the moment it will have to stay on 150dpi until I figure it out as its holding development up. 150dpi may take 5 seconds per page instead of 2 seconds, but luckily its not time critical.

Thanks,
Leon
 
If you're using PrintDocument you can also set qualities for the e.Graphics object. Here you may also draw the text directly on top of the image in print out rather than first draw to image then draw image to print.
 
Thnaks for that! I wonder if I should check out the other method (when printing) in that case.... Thanks!
 
If you're using PrintDocument you can also set qualities for the e.Graphics object. Here you may also draw the text directly on top of the image in print out rather than first draw to image then draw image to print.

This worked!!! I'm not sure why its different, but simply using the Drawstring function within the 'printpage' routine has overlayed my image with perfect looking text... I can set the 'background image' to 96,96 and the text still looks fine!!

Thanks!! Any ideas why this is?

I would give you another good feedback but I have to 'spread the feedback' apparently ;)
 
Back
Top