我想用GDI打印我的表单,但是当我打印它时,打印质量不是很好(不知道是否图像获取别名?),窗体大小为700x700,也有其力理解-raster运算代码 - 一个参数,这里是我的代码使用...如何提高打印质量当我打印在Win中的窗体在C#
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g1 = this.CreateGraphics();
System.Drawing.Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
Bitmap bmp = new Bitmap(MyImage);
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = bmp.Width;
int height = bmp.Height;
if ((width/e.MarginBounds.Width) > (height/e.MarginBounds.Height))
{
width = e.MarginBounds.Width;
height = bmp.Height * e.MarginBounds.Width/bmp.Width;
}
else
{
height = e.MarginBounds.Height;
width = bmp.Width * e.MarginBounds.Height/bmp.Height;
}
System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
e.Graphics.DrawImage(bmp, destRect, 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel);
}
在纸上也使它成为700 x 700像素。这将是锋利的,但不幸的是,你需要一个放大镜才能看到它。不要打印表格。 –
@Hans Passant:这让我的问题变得更糟.. :(..然后我必须从我的代码中打印一个PDF文件,而没有在机器上安装任何PDF阅读器...这是可能的C#..? –