月夜钓钱江鱼

醉后不知天在水,满船清梦压星河。
posts - 50,comments - 8,views - 29026

打印过程中,获取可见的实际宽度作为打印,就没有收缩的了,图片收缩放大是模糊的原因之一,所以所见所得就是最好的方法

复制代码
 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         }
复制代码

 

posted on   湘灵  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示