我想要实现的是使用itextsharp隐藏图像(通过不透明度或透明度)。到目前为止,图像显示如下:
string webURL = "X:/XXXXXX/web.png";
iTextSharp.text.Image webIcon = iTextSharp.text.Image.GetInstance(webURL);
webIcon.Annotation = new Annotation(0,0,0,0, "http://www.xxxxx.com");
webIcon.ScaleAbsolute(35f, 35f);
webIcon.SetAbsolutePosition(227,23);
webIcon.Transparency = new int[] {0,0 };
//state.FillOpacity = 0.2f;
//webIcon.GrayFill = 0.2f;
doc.Add(webIcon);
如何更改透明度以使图像的可见性为空?
答案 0 :(得分:0)
您需要使用PdfGState
。在你的情况下:
var writer = PdfWriter.GetInstance(document, output);
document.Open();
string webURL = "http://www.apache.org/foundation/press/kit/feather.png";
Image webIcon = Image.GetInstance(webURL);
webIcon.Annotation = new Annotation(0, 0, 0, 0, "http://www.google.com");
webIcon.ScaleAbsolute(35f, 35f);
webIcon.SetAbsolutePosition(227, 23);
PdfContentByte canvas = writer.DirectContentUnder;
canvas.SaveState();
PdfGState state = new PdfGState();
state.FillOpacity = 0.6f; // THIS is where you set opacity
canvas.SetGState(state);
canvas.AddImage(webIcon);
canvas.RestoreState();
document.Close();
希望有所帮助