tags:

views:

14

answers:

1

Hi all:

I have a print preview that displays a captured panel on a form 'Panel1.DrawToBitmap(memoryImage, bounds);'

I also save the image to my hard drive - 'memoryImage.Save("diary.png")'

The image in the print preview at any zoom level is blurry, the saved image is perfect (viewed in windows photo viewer & PS).

Id like the print preview to be as good as the saved image, any ideas?

here's the code:-

    private void CaptureScreen()
    {
        int x = splitContainerDiary.Location.X;
        int y = splitContainerDiary.Location.Y;

        int SCwidth = splitContainerDiary.Panel1.Width;
        int SCheight = splitContainerDiary.Panel1.Height;

        Rectangle bounds = new Rectangle(x, y, SCwidth, SCheight);

        memoryImage = new Bitmap(SCwidth, SCheight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        splitContainerDiary.Panel1.DrawToBitmap(memoryImage, bounds);
        memoryImage.Save("diary.png");
    }

    private void printDocumentDiary_PrintPage(object sender, PrintPageEventArgs e)
    {
        CaptureScreen();
        Font HeaderFont = new Font("Consolas", 16, FontStyle.Bold);
        e.Graphics.DrawString(selectedYear.ToString() + " - " + name, HeaderFont, Brushes.Black, 15, 15);
        e.Graphics.DrawImage(Image.FromFile("diary.png"), 5, 5);
     //   e.Graphics.DrawImage(memoryImage, 0, 40);
        PrintDoodle(e);
    }

I have tried to draw the image from memory (e.Graphics.DrawImage(memoryImage, 0, 40) and also from the saved image 'e.Graphics.DrawImage(Image.FromFile("diary.png"), 5, 5);' They are both blurry in print preview.

I have tried different Pixel formats with no joy either.

I have tried saving the image as BMP, JPG, PNG with no joy either (when drawing image fromFile).

I have tried using BitBlt routine also with the same results.

Tino

A: 

This is an inevitable consequence of the dramatic difference between the device resolution of a printer vs a monitor. A printer typically can print with a resolution of 600 dots per inch. A monitor is typically set to 96 DPI. So when you print an image that's razor sharp on a monitor, each pixel of the image requires printing a blob of 6 x 6. Short from the blockiness this produces, anything that's drawn on screen with anti-aliasing will get those anti-aliasing pixels drawn 6 times larger as well. Completely ruining the effect. This is especially noticeable with any text that's drawn with ClearType anti-aliasing. The red and blue fringes become very noticeable on paper.

You can partly solve this by drawing the image one-to-one on the printer, ensuring that 1 pixel in the image becomes 1 pixel on paper. That ought to now look nice and sharp (minus the ClearType problem) but you'll be looking at a postage stamp. Growing your arms six times longer would have the same effect.

Well, this just doesn't work well. Use the PrintDocument class so you can draw stuff to the printer using its native resolution. Use the methods provided by e.Graphics in the PrintPage event handler. Avoid images unless they are photos, anything that doesn't have finely detailed line art will scale well.

Hans Passant
Hans thank you for your answer, not what I was hoping for but I get the point now. Im printing a 12 month datagidview diary, each month with a cell for each day so its going to take some work to use e.graphics drawing methods :-( So I think i'll stick with the blur for now. Thankyou once again, Tino
Tino Mclaren