如何在iText中将图像的颜色更改为一种颜色?

时间:2019-11-05 09:37:26

标签: c# asp.net itext

我正在将图像添加到pdf文档中,并且需要使图像颜色与文本相同。例如,如果文本颜色为绿色,则整个图像也必须为绿色。

我尝试在线搜索,但没有找到有关如何在itext中更改图像颜色的答案。我是itext的新手,因此我非常感谢您的帮助。

     var logo = Image.GetInstance(logoBytes);
     logo.PaddingTop = 0;
     var imageWidth = Convert.ToDouble(element.width) * Convert.ToDouble(element.scaleX);
     var imageHeight = Convert.ToDouble(element.height) * Convert.ToDouble(element.scaleY);
     var widthRatio = imageWidth / canvasWidth;
     var heightRatio = imageHeight / canvasHeight;
     var finalWidth = (float)envelopeWidth * 72 * ((float)imageWidth * 72 / 96) / (canvasWidth * 72 / 96);
     var finalHeight = (float)envelopeHeight * 72 * ((float)imageHeight * 72 / 96) / (canvasHeight * 72 / 96);
     var finalTop = (float)envelopeHeight * 72 * (element.top  * 72 / 96) / (canvasHeight * 72 / 96);
     var finalLeft = (float)envelopeWidth * 72 * (element.left * 72  / 96) / (canvasWidth * 72 / 96);
     var imageLeft = finalLeft + lpage.ArtBox.Left;
     envelopeBottom = lpage.ArtBox.Top + 40;
     var imageTop = envelopeBottom + (float)(envelopeHeight * 72) - Convert.ToDouble(finalTop) - finalHeight;
     logo.ScaleToFit((float)finalWidth, (float)finalHeight);
     logo.SetAbsolutePosition((float)imageLeft, (float)imageTop);
     doc.Add(logo);

我成功地使页面的文字变成了我想要的颜色,而不是图像。

0 个答案:

没有答案
相关问题