2011-03-08 15 views
1

我有一些麻煩打印具有8位alpha通道的圖像和文本。
它看起來像大多數打印機驅動程序將錯誤地呈現alpha通道,添加一些抖動模式,而不是混合各個層。
例如,此問題末尾的代碼會產生如下所示的內容(請注意左側正方形中的抖動):Virtual PDF printer - Laser printer
到目前爲止,只有XPS虛擬打印機才能正常工作。使用部分透明度打印圖像而不引入扭曲

我一直爲避免這種情況而做的是在中間位圖上打印,但對於1200 DPI的標準11x8.5'頁面,只需要大約400 MB的RAM來存儲此位圖,而我現在想知道哪種打印方式是正確的。
感謝

using System; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Drawing.Printing; 
using System.Windows.Forms; 

class Program 
{ 
    static void Main(string[] args) 
    { 
     PrintDocument printDoc = new PrintDocument(); 
     printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); 

     PrintDialog print = new PrintDialog(); 
     print.Document = printDoc; 
     if (print.ShowDialog() == DialogResult.OK) 
      printDoc.Print(); 
    } 

    static void printDoc_PrintPage(object sender, PrintPageEventArgs e) 
    { 
     //draw directly on the print graphics 
     e.Graphics.TranslateTransform(50, 50); 
     drawStuff(e.Graphics); 

     //draw on an intermediate bitmap 
     e.Graphics.ResetTransform(); 
     using (Bitmap bmp = new Bitmap((int)e.Graphics.DpiX, (int)e.Graphics.DpiY)) 
     { 
      bmp.SetResolution(e.Graphics.DpiX, e.Graphics.DpiY); 
      using (Graphics g = Graphics.FromImage(bmp)) 
      { 
       g.ScaleTransform(e.Graphics.DpiX/100, e.Graphics.DpiY/100); 
       drawStuff(g); 
      } 
      e.Graphics.DrawImageUnscaled(bmp, new Point(175, 50)); 
     } 
    } 

    private static void drawStuff(Graphics graphics) 
    { 
     Brush b1 = new SolidBrush(Color.LightGray); 
     Brush b2 = new SolidBrush(Color.FromArgb(50, Color.Black)); 
     graphics.FillRectangle(b1, new Rectangle(0, 0, 100, 100)); 
     graphics.FillRectangle(b2, new Rectangle(25, 25, 50, 50)); 
    } 
} 

回答

0

您可以使用庫如iTextSharp的?該庫有一堆不同的類,可以處理圖像和字體。