2013-12-17 65 views
0

我需要將PDF轉換爲透明度的GIF。我在official site上發現了一些代碼示例,但結果與預期不符。常見的問題是透明度下降。AbcPdf pdf保持透明度的GIF轉換

我嘗試下面的代碼:

using (var doc = new Doc()) { 
      doc.Read(source); 
      doc.Rendering.SaveAlpha = true; 
      // the following lines from the official site. 
      // And this is showing blue background if I set this. 
      // But I don't need this blue background. 
      // Do not set anything special won't give good result. 

      //doc.Color.SetRgb(0, 0, 255); // blue background ... 
      //doc.FillRect(); // ... so you can see transparency 

      doc.Rendering.Save(destination); 
      doc.Clear(); 
     } 

請幫助,如果任何人有這樣的經驗研究。謝謝

回答

2

Rendering.SaveAlpha屬性不適用於GIF。

GIF文件中的顏色定義存儲在調色板中,而不是通道。調色板可以包含多達256種顏色,其中一種顏色設置爲透明。不同於使用alpha通道,沒有透明度。每個像素將是不透明的顏色或透明。

要保留Alpha通道,您需要呈現其他格式,例如PNG,BMP,TIFF(灰度,RGB和CMYK)或Photoshop PSD。如果結果看起來不錯,請將其轉換爲透明的GIF,但我希望您會發現一些透明度信息將會丟失。這是不可避免的。

+0

我不專注於AbcPdf。我需要轉換可能的任何其他工具或庫。 – alex