Click here to Skip to main content
15,902,937 members
Please Sign up or sign in to vote.
4.67/5 (2 votes)
See more:
I have a problem with my text quality after printing ! it's not smooth and antialiases!

This is the story :

I create a graphic from a bitmap (Graphics.FromImage(MyBitmap)) and I think it's the start point of my problem because I can't use PrintPageEvenArg(e) , but I have no other choice!

after that I begin writing some text on this graphic:

by reading the answers of similar Questions in this site and some others , I made some changes on my graphics properties such as smoothingMode , TextRenderingHint , ... that U see in continue... but unfortunately none of them helped me !

SolidBrush sb = new SolidBrush(Color.White);
  graphics.FillRectangle(sb,oRectangle); //it was suggested to be done before antialiases inorder to get effects

  graphics.TextRenderingHint = TextRenderingHint.AntiAlias; //I also tried ClearTypeGridFit
  graphics.SmoothingMode =
        System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
  graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
  graphic.CompositingQuality = CompositingQuality.HighQuality;
  graphic.CompositingMode = CompositingQuality.SourceOver;

  Graphics.DrawString(strValue, boxStyle.Font, sb, oRectangle, StringFormat);
<
by antialising I got better smooth edge but I see a lot of extra pixel near my text and my text color seems to become lighter so I can say that by smoothing edge my text quality even got worse !

I also used different image Formats such as png , jpg , bmp , ... but not helped!

plz help me ! Thanx in advance :)
Posted
Comments
lukeer 25-Jul-12 5:38am    
First question is: Why can't you use PrintPageEventArgs?

Second: I doubt this is your actual source code since graphics, graphic and Graphics are strangely mixed besides that it wants to draw the text with the same brush that was used for background.
Could you please Improve on your question using the "Improve question" link and shed some light on the mentioned details?
johannesnestler 3-Dec-13 9:42am    
So the most important question stays: Why can't use use PrintPageEventArgs? If you really can't (...) you could instead create a flowdocument an XPS or just a html-Page, something else than a Bitmap to print... BTW. you didn't mention UI Technology used but I assume WinForms? omg - just saw now how old the question is - sorry Forget it...

It's not entirely clear what you're doing, so are you saying that you're writing this text to an image and then printing the image??

Yeah, that's going to severely screw up any aliasing you do. Why??

Because the image that you're drawing on is 96 DPI and when you print that image on something capable of far greater resolution, say a 1600 DPI printer, the image is being blown up (magnified).

If you show your bitmap on the display, it's say, 2 inches wide. When you print that 96 DPI image on a printer in its native resolution, that image is now less than a quarter inch wide. You have to magnify the image, and therefore every pixel, to get it to be 2 inches wide again on the printer.

Every pixel goes from being .010 inches wide on your monitor to being .000625 inches wide on your printer. With the magnification to get each pixel back up to .010, you have to multiply the width of every pixel in the image by a factor of 16. That just wiped out your anti-aliasing.
 
Share this answer
 
Comments
shimashim 26-Jul-12 15:19pm    
@Dave :
yes , exactly !

thanx for your explanation , but with these circumstance do U have any advice for me to solve this prob ?
Dave Kreskowiak 26-Jul-12 16:21pm    
You cannot create a Bitmap object big enough to print a page at the printers native resolution. You're ONLY alternative is the one you say you cannot use, drawing directly to the printer graphics object you get in PrintEventArgs.

shimashim 26-Jul-12 16:37pm    
anyway , thanx for Ur help :)
Use this:

graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
graphics.DrawString(...

worked for me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900