Re: Drawing Small Text with Very High Quality in GDI+
- From: SharpCoderMP <csharp_mp@xxxxxxxxxxxxxxxx>
- Date: Mon, 03 Oct 2005 10:42:52 +0200
Houston wrote:
> As a test, I opened up MSWord and set the font and size, which happens to be
9pt Courier New for this case. When I did a print preview and zoomed in 500%, no jaggies, looked like perfect blown up text and printed fine. When I did the same operation within IE and my application(print preview and blew up to 500%), you could see the pixels on any diagonal.in ms word preview is generated dynamicaly from vector fonts. when you draw to bitmap you get pixels instead of curves, so when you zoom in your bitmap you just get bigger pixels.
i'd suggest creating button on your web page "printable version" that will feed browser with higher resolution image for printing purpouses that has the same size set inside <img> tag - just like Lloyd suggested.
the browser will take care of resizing your bitmap to display correctly. but remember not to dump your high res image every time when user views your page - this will kill your server and bandwidth.
So, the objective here is for me to see if anyone knows how to really pump a ton of pixels into an image and get it to print super HQ smal font.
Ok, so where I'm at now and what I've already tried. I created a new web project for testing and started with a very basic example Bob Powell had on his site. I added some small changes for throwing the image out to a webpage.
<code> private void Page_Load(object sender, System.EventArgs e) { //Create a high resolution image... Bitmap bm=new Bitmap(600 , 400);
bm.SetResolution(100, 100);
//Get a Graphics for it Graphics g=Graphics.FromImage(bm);
//set up the graphics. g.PageUnit=GraphicsUnit.Point;
//clear to white g.Clear(Color.White);
//Testing around
/*
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
*/
//Create a 14 point font.. Font fn=new Font("Courier New", 9, GraphicsUnit.Point);
Hashtable ht = new Hashtable();
foreach(FontFamily f in FontFamily.Families) { ht.Add(f.Name, f.Name); }
//output text
g.DrawString(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer dignissim, nisl et imperdiet blandit, dolor ",
fn,
Brushes.Black,
new RectangleF(0,0,72*5,72*5),
StringFormat.GenericTypographic);
ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
Response.ContentType = "image/jpeg"; Response.Charset = "" ;
// Throw image out to webpage bm.Save(Response.OutputStream, ici, eps); bm.Dispose(); }
private ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders();
for(j = 0; j < encoders.Length; ++j) { if(encoders[j].MimeType == mimeType) return encoders[j]; } return null; } </code>
Ok, this will generate what I'm wanting things to look like visually on screen, but doesn't print well. I've tried: playing with the resolution, creating the image very large and resizing it, switching image types(gif, jpeg), and different properties of the graphics seen under the testing comment in the code above.
Any help or ideas would be greatly appreicated.
.
- References:
- Drawing Small Text with Very High Quality in GDI+
- From: Houston
- Drawing Small Text with Very High Quality in GDI+
- Prev by Date: Re: Drawstring word-wrap
- Next by Date: Re: Drawstring word-wrap
- Previous by thread: Re: Drawing Small Text with Very High Quality in GDI+
- Next by thread: Re: TextBox Drawing Bounds
- Index(es):
Relevant Pages
|