Click here to Skip to main content
15,902,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I am going to create a bitmap image and draw a text but the quality of the image for printing purpose is low and the pixels are visible and are not like when i print through microsoft word.

the following is part of the code that we use.

Please let me know if you have any solution.

Thanks
C#
MyBitmap =new System.Drawing.Bitmap(GetMaxWidthOfReport(), MyActualPageSizeInfo.Height);

MyGraphics =System.Drawing.Graphics.FromImage(MyBitmap);
			
Mygraphics.TextContrast = 4; // Default: [4], Must be between 0 - 12
Mygraphics.PageUnit = System.Drawing.GraphicsUnit.Display; // Default: [Display]
Mygraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Default: [None]
Mygraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // Default: [Default]
Mygraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; // Default: [SourceOver]
Mygraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; // Default: [Default]
Mygraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; // Default: [Bilinear]

Mygraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
Posted
Updated 30-May-12 4:13am
v3
Comments
OriginalGriff 30-May-12 8:25am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Show us the code you use to load the image, write on it, and try providing a link to the sample image before and after so we can see what you mean.
Use the "Improve question" widget to edit your question and provide better information.

Please see my previous solution to an analogous question here on CP: How to make high qaulity image with text in C#: Solution 1[^].

You may want to also look at this article here on CP Custom AntiAliasing with GDI+[^] by Keith Rule[^].

Regards,

Manfred
 
Share this answer
 
Comments
albert sh 30-May-12 9:46am    
HiThank you for your kind reply, I used antialias and also cleartypeGridfit but they made showing the words worse in the image, the following is part of the code:

MyBitmap =new System.Drawing.Bitmap(GetMaxWidthOfReport(), MyActualPageSizeInfo.Height);

MyGraphics =System.Drawing.Graphics.FromImage(MyBitmap);

Mygraphics.TextContrast = 4; // Default: [4], Must be between 0 - 12
Mygraphics.PageUnit = System.Drawing.GraphicsUnit.Display; // Default: [Display]
Mygraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Default: [None]
Mygraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; // Default: [Default]
Mygraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; // Default: [SourceOver]
Mygraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; // Default: [Default]
Mygraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; // Default: [Bilinear]

Mygraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
Some times changing interpolation method or AntiAlias do not changes things much.
Because they only improve the situation.

Image resolution, image size and screen resolution are related to print good quality images. Please try the following example.

1) Lets assume that your screen resolution is 96 dpi (or 72 dpi?)
2) If you want to print the image in normal quality with 5 inches-long physical sizes in each side, you should have the image size AT LEAST 5 x 96 pixels in each directions (X, Y). If you have more pixels the quality of the printed image would be better and clear.

3) First, please create larger Bitmap with higher dpi (above 96 is better). The image size, in terms of number of pixels, should be larger than the "Screen Resolution x Physical Size after printing".

(Notice "x" indicates multiplication).

Regards.
 
Share this answer
 
Comments
albert sh 30-May-12 11:51am    
Thank you for you reply.

After creating larger image size the only thing that happens is smaller word size in larger area , I have tried it before but unsuccessful
MuhtarQong 30-May-12 12:06pm    
Please tell me your word(12pt, 18pt, or how big) size and image size to be expected or trying to print. I will do it and answer you in this site.
Regards.
albert sh 31-May-12 4:23am    
HiThank you for your kind reply, the user selects the font size but you assume 10pt and the image size is the same as paper size.

please let us have your sample code to do it.
Many thanks
albert sh 25-Feb-13 11:21am    
Dear muhtarqong
Please let me have your final opinion, as the problem still exists
Thanks
You need to make the bitmap large enough, remembering that a printer will expect a higher DPI than the screen (at least 300). It probably makes more sense to draw to the printer's graphics object directly, e.g. in a PrintDocument.PrintPage event handler.
 
Share this answer
 
Comments
albert sh 30-May-12 14:33pm    
Thanks Bob
The problem with the printdocument is this : when the number of pages increases it will slow down,

please let me know if I use larger bitmap size how I can scale it to fit on paper?

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