我想用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#..? –