Re: Printing Problem!
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 16 Jul 2007 10:10:31 -0700
On Mon, 16 Jul 2007 04:07:49 -0700, mehdi <mehdi.mousavi@xxxxxxxxx> wrote:
[...]
However, something is really wrong with the above code since both of
those lines (commented out as 1 & 2), are neither anti-aliased nor
smooth. But if I draw the lines this way, everything is perfect:
Graphics g = e.Graphics;
Rectangle rc = new Rectangle(0, 0, 827, 1169);
g.DrawLine(Pens.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //Line 1
g.DrawLine(Pens.Black, rc.Right, rc.Top, rc.Left, rc.Bottom); //Line 2
This has very little to do with printing and everything to do with the difference between drawing to a bitmap first and drawing directly to an output device (any output device, whether the screen or a printer).
When you draw into the bitmap, you necessarily limit the resolution of your lines to the resolution of the bitmap. In this case, that appears to be 100 dpi (by default the Graphics in the PrintPageEventArgs is already 100 dpi). 100 dpi isn't really all that high resolution, and is usually much lower than whatever the printer will be printing at.
For example, I've got a couple of ink jet printers here, one is some ten years old, and for both of them the _draft_ mode is 360 dpi, with puts approximately 10 times as many pixels into the same area as 100 dpi does..
So, in the code you posted, you're limiting the resolution of the lines to 100 dpi, while when you draw directly to e.Graphics, you use whatever resolution the printer is printing at (which is almost certainly considerably higher than 100 dpi).
Thus, jaggies the first way, smooth lines the second.
Note: just because the resolution reported by e.Graphics is 100 dpi, that doesn't mean that's the actual output resolution. That just happens to be the coordinate resolution with which your drawing will occur. It's similar to setting the resolution and pixel measurement when drawing to the screen; you aren't limited by the resolution with which you specify drawing coordinates...only the resolution of the output device matters (unless, of course, you run your graphics primitives through a lower-resolution bitmap first, as you're doing here).
The moral of the story: if you want the best results, draw directly to the output device, rather than to a bitmap first. That allows the output device to take full advantage of the basic graphics primitives you're using to compose the output.
Pete
.
- References:
- Printing Problem!
- From: mehdi
- Printing Problem!
- Prev by Date: charting
- Next by Date: Re: Calling an exe from C#
- Previous by thread: Printing Problem!
- Next by thread: problem measuring width of TabPage.Text
- Index(es):
Relevant Pages
|