Click here to Skip to main content
15,997,509 members
Please Sign up or sign in to vote.
2.78/5 (3 votes)
See more:
Hi I am trying to take a print from the picture box when i see the preview of that image after pressing the print button it is not coming proper the quality of the image is coming very bad
I tried the following
picTrade is the picture box
VB
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim bm As New Bitmap(picTrade.ImageLocation)
        picTrade.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
        e.Graphics.DrawImage(bm, 0, 0)
        e.Graphics.PageUnit = GraphicsUnit.Inch
End Sub
Posted
Updated 29-Jul-20 5:37am
v3

1 solution

just a hint, but I sugest you to dive into the options of the graphics object! you will need to set some options for better image quality like shown below (just an example). and, you should probably print from the source of your image box, e.g. by loading the hopefully "high quality" source into a bitmap. remember, screen elements on windows are drawn 96dpi (default) only (maybe still 72dpi mac os!?). so printing them at 300dpi on paper will result in either very small pictures or (bad) resized and blur images. further more you will have to bother with blurry results esp. blurry fonts, this may relate to an issue to be found under the keyword SnapsToDevicePixels (e.g. on WPF UIElements) because a pixel may have device specific dimensions. same for saving images (see encoder parameters). having written my own printing module I can tell you, printing is no easy job.

C#
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
    //set the resize quality modes to high quality
    graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality
    //draw the image into the target bitmap
    graphics.DrawImage(image, 0, 0, result.Width, result.Height);
}


one more thing, don't draw in inch test with some native units like GraphicsUnit.Pixel (I think that implies snaptodevicepixel) see http://msdn.microsoft.com/de-de/library/system.drawing.graphicsunit(v=vs.110).aspx[^]
 
Share this answer
 
v2
Comments
surajemo 22-Apr-14 1:48am    
Hey Thank u for replying but i am opening that image file in paint quality is coming good

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