Hi,
Consider a printing scenario where I have to draw the entire page on a
827x1169 (.01 inch) size. Thereafter, the entire bitmap has to be
resized to fill a given Bounds rectangle (keeping the aspect ratio
fixed). To do so, I've just wrote the following code in the PrintPage
event:
Graphics g = e.Graphics;
Rectangle bounds = TheDestinationRectangle;
Rectangle rc = new Rectangle(0, 0, (Int32)(827 * g.DpiX / 100), (Int32)
(1169 * g.DpiY / 100));
using (Bitmap img = new Bitmap(rc.Width, rc.Height))
{
using (Graphics bmp = Graphics.FromImage(img))
{
bmp.DrawLine(Pens.Black, rc.X, rc.Top, rc.Right, rc.Bottom); //
Line 1
bmp.DrawLine(Pens.Black, rc.Right, rc.Top, rc.Left,
rc.Bottom); //Line 2
g.DrawImage(img, bounds, rc, GraphicsUnit.Pixel);
}
}
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
What am I doing wrong?
Any help would be highly appreciated,
TIA,
Mehdi