iText7 - 无法设置 SquareAnnotation 内部颜色的不透明度 [英] iText7 - unable to set the the Opacity for SquareAnnotation Interior color

查看:25
本文介绍了iText7 - 无法设置 SquareAnnotation 内部颜色的不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队,我正在使用 iText7 C# 库.我无法为 Square Annotation InteriorColor 设置不透明度.

Team, I am working with iText7 C# library. I am not able to set the Opacity for the Square Annotation InteriorColor.

下面是我正在使用的代码.我尝试了使用 SquareAnnotation 的所有不同方法来设置不透明度,但没有运气.我错过了什么吗?

Below is the code I am using. I tried with all the different methods we have for a SquareAnnotation to set the Opacity but, no luck. am I missing anything?

private PdfSquareAnnotation AddAnnotation(float rectHeight, float rectWidth, float x, float y)
    {
        Rectangle rect = new Rectangle(x, y, rectWidth, rectHeight);
        PdfSquareAnnotation squareAnnotation = new PdfSquareAnnotation(rect);
        squareAnnotation.SetColor(ColorConstants.GREEN);
        squareAnnotation.SetTitle(new PdfString("This is the title"));
        squareAnnotation.SetContents("This is the contents of the annotation. bla bla..");
        squareAnnotation.SetNonStrokingOpacity(25);
        squareAnnotation.SetOpacity(new PdfNumber(30));
        squareAnnotation.SetInteriorColor(new float[] { (float)0.294, (float)0.552, (float)0.968 });

        //squareAnnotation.SetStrokingOpacity(25);


        return squareAnnotation;
    }

输出:

未应用内部颜色的不透明度

Opacity for interior color is not being applied

提前致谢

推荐答案

原因是您使用了不透明度值 25 和 30 - 不透明度值范围是 0.0(完全透明)到 1.0(完全不透明).因此,25 和 30 实际上是过于不透明.

The cause is that you use opacity values 25 and 30 - the opacity value range is 0.0 (fully transparent) to 1.0 (fully opaque). Thus, 25 and 30 effectively are excessively opaque.

通过切换到

squareAnnotation.SetNonStrokingOpacity(0.25f);
squareAnnotation.SetOpacity(new PdfNumber(0.30f));

您将获得所需的部分透明度.

you get the desired partial transparency.

这篇关于iText7 - 无法设置 SquareAnnotation 内部颜色的不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆