none
html 转成bitmap 调用printdocument 进行打印 但是打印出的失真了 RRS feed

  • 问题

  • web生成html文件,是一个10x10的标签。

    我按照网上的代码将html转成图片,再用printdocumen打印,结果打印出来的标签很模糊。

    如果直接调用webbrowser打印则很清晰,请教下是什么原因?(或者有没有其他的方式将html直接打印出来)

    主要代码如下:

     PrintDocument pdoc = new PrintDocument();
    pdoc.PrintPage += new PrintPageEventHandler(this.pdoc_PrintPage);
     PrintController pctl = new StandardPrintController();
    pdoc.PrintController = pctl;
    pdoc.Print();
    
     private void pdoc_PrintPage(object sender, PrintPageEventArgs e)
            {
                e.HasMorePages = false;
    
                string strHtml = "";
                //strHtml = GetHTML(str);
                strHtml = GetHtmlCSS();
    
                GetImage thumb = new GetImage(strHtml, 393, 393, 393, 393);
                System.Drawing.Bitmap bp = thumb.GetBitmap();
                int width = bp.Width;
                int height = bp.Height;
    
                Rectangle destRect = new Rectangle(0, 0, width, height);
                e.Graphics.DrawImage(bp, destRect, 0, 0, 100, 100, System.Drawing.GraphicsUnit.Millimeter);
            }
    
     Bitmap myBitmap = new Bitmap(Width, Height);
                Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
                MyBrowser.DrawToBitmap(myBitmap, DrawRect);
                System.Drawing.Image imgOutput = myBitmap;
                System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
                Graphics g = Graphics.FromImage(oThumbNail);
                Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
                g.DrawImage(imgOutput, oRectangle);
                    return (Bitmap)oThumbNail;



    2016年6月17日 11:39

答案

  • Hi,

    你确认过转换出来的图片是原图吗?(未经过缩放)请问能否提供些对比图片?

    另外,你可以试试用下面的代码来调节图像质量(放置于DrawImage方法前):

                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    2016年6月20日 8:33