首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

drawImage失真,该怎么处理

2012-10-20 
drawImage失真直接在打印中drawstring,字体不失真,若先外部整理成image,然后再通过drawimage字体就非常模

drawImage失真
直接在打印中drawstring,字体不失真,若先外部整理成image,然后再通过drawimage字体就非常模糊,为什么?

C# code
private void button1_Click(object sender, EventArgs e)        {            PrintDocument printDocument = new PrintDocument();            printDocument.DocumentName = "测试文档";//设置完后可在打印对话框及队列中显示(默认显示document)            //打印输出(过程)                        printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);            PrintPreviewDialog ppd = new PrintPreviewDialog();            ppd.Document = printDocument;            try            {//显示打印预览窗口                ppd.WindowState = FormWindowState.Maximized;                ppd.ShowDialog();            }            catch (Exception excep)            {                //显示打印出错消息                MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);            }        }        Bitmap imageDraw()        {            Bitmap bitmap = new Bitmap(50, 50);            SolidBrush drawBrush = new SolidBrush(Color.Black);            StringFormat drawFormat = new StringFormat();            using (Graphics g = Graphics.FromImage(bitmap))            {                g.DrawString("小字体测试", new Font("宋体", 6), drawBrush, 2, 2, drawFormat);            }            return bitmap;        }        void printDocument_PrintPage(object sender, PrintPageEventArgs e)        {            Graphics g = e.Graphics;            // 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。              g.InterpolationMode = InterpolationMode.HighQualityBicubic;            // 指定高质量、低速度呈现。              g.SmoothingMode = SmoothingMode.HighQuality;            Bitmap image = imageDraw();            g.DrawImage(image, new Rectangle(100, 100, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);            SolidBrush drawBrush = new SolidBrush(Color.Black);            StringFormat drawFormat = new StringFormat();            g.DrawString("直接刷字测试", new Font("宋体", 6), drawBrush, 200, 200, drawFormat);            e.HasMorePages = false;        }


[解决办法]
前者以文字方式打印,后者以图像方式打印,文字可保真,图像会因适应打印分辨率而失真。

热点排行