2009-07-22 44 views
0

当我试图打印图像到700kb文件的打印机时,它发送120MB数据到打印机。我可以看到这个,因为我看到打印机假脱机120MB。为什么会发生这种情况?PrintDocument假脱机到打印机的方式很大

下面是PrintDocument.PrintPage

private void PrintPage(object sender, PrintPageEventArgs ev) 
{ 
       sw.WriteLine("start,PrintPage," + DateTime.Now.ToLongTimeString()); 

       if (_running && _currentPage != null) 
       { 
        RectangleF PrintArea = ev.Graphics.VisibleClipBounds; 
        RectangleF NewImageSize = new RectangleF(); 
        Double SF = Convert.ToDouble(PrintArea.Width)/Convert.ToDouble(_currentPage.Width); 
        NewImageSize.Width = Convert.ToInt32(_currentPage.Width * SF); 
        NewImageSize.Height = Convert.ToInt32(_currentPage.Height * SF); 

        //You can influence the quality of the resized image 
        ev.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
        ev.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; 
        ev.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default; 
        //Draw the image to the printer 
        ev.Graphics.DrawImage(_currentPage, NewImageSize); 
        _currentPage.Dispose(); 
        _currentPage = null; 

        //Trace.WriteLine(string.Format("IsFinished {0}, Count {1}", (_queue.IsFinished ? "True" : "False"), _queue.Count)); 
        ev.HasMorePages = (!((_queue.IsFinished) && (_queue.Count == 0)));      
       } 
       sw.WriteLine("end,PrintPage," + DateTime.Now.ToLongTimeString()); 

      } 

回答

1

代码有两个原因,打印的图像比图像文件大:

的图像文件很可能被压缩。如果是JPEG图像,通常会压缩到其大小的1/10 - 1/20。当你加载图像时,它被解压缩到10MB左右。

当您将图像发送到打印机时,您正在调整图像大小。打印机的分辨率通常很高。如果图像的分辨率为300PPI,打印机的分辨率为1000PPI,则图像的尺寸将调整为原始尺寸的十倍。

+0

有关提高性能的任何建议?目标是必须保持字母的清晰度 – greektreat 2009-07-22 19:52:24

0

我不太了解.Net,但我相信System.Drawing函数是建立在GDI +之上的。 GDI +在CPU上执行大量渲染并将位图传输到目标设备。在现代系统上,当瞄准图形显示时,这很好。不幸的是,它没有太多机会利用设备的功能(或其驱动程序的功能)。

许多打印机,例如,直接支持JPEG和PNG。使用GDI而不是GDI +时,您可以确定打印机是否具有此类支持,并传输原始JPEG并让打印机进行解压缩和调整大小。这仍然是一些工作,对于那些没有这种支持的打印机,您仍然需要慢速的方法。

相关问题