打印过程中,获取可见的实际宽度作为打印,就没有收缩的了,图片收缩放大是模糊的原因之一,所以所见所得就是最好的方法
1 private void printDocNew_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 2 { 3 Graphics g = e.Graphics; 4 5 g.Clear(Color.White); 6 7 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 8 g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; 9 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 10 // 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。 11 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 12 // 指定高质量、低速度呈现。 13 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 14 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; 15 16 int sz = (int)g.VisibleClipBounds.Width;//关键代码,获取可见的实际宽度 17 Bitmap img = Zxing_QRCode(txtQrContent.Text.Trim(), sz, sz); 18 19 Bitmap imgP = GetImagePure(img); 20 21 int destSize = (int)(g.VisibleClipBounds.Width * 0.8); 22 23 Rectangle rectDest = new Rectangle(img.Width / 2 - destSize / 2, img.Height / 2 - destSize / 2, destSize, destSize); 24 25 e.Graphics.DrawImage(imgP, rectDest); 26 27 imgP.Dispose(); 28 img.Dispose(); 29 30 string txt = txtBottomText.Text.Trim(); 31 if (txt != "") 32 { 33 SizeF sf = g.MeasureString(txt, FontText); 34 g.DrawString(txt, FontText, Brushes.Black, g.VisibleClipBounds.Width / 2 - sf.Width / 2, rectDest.Bottom);//2 * 35 } 36 }