LinearGradient 不会作为最终颜色透明
LinearGradient not going transparent as end color
我已经这样设置了我的 LinearGradient
TextPaint paintText = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paintText.setColor(Color.WHITE);
paintText.setTextSize(size);
paintText.setStyle(Paint.Style.FILL_AND_STROKE);
paintText.setShadowLayer(3f, 3f, 3f, Color.BLACK);
int pL = bitmap.getWidth() / 100;
int pT = bitmap.getHeight() / 100;
StaticLayout mTextLayout = new StaticLayout(
gagTitle,
paintText,
newCanvas.getWidth(),
Layout.Alignment.ALIGN_NORMAL,
1.0f,
0.0f,
false);
int dummyHeight = mTextLayout.getHeight();
Shader shader = new LinearGradient(0, 0, 0, (dummyHeight * 2), Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR);
Paint paint = new Paint();
paint.setShader(shader);
newCanvas.drawRect(new RectF(0, 0, bitmap.getWidth(), dummyHeight), paint);
我不知道为什么,但在生成的渐变结束时,除了透明之外,它没有那么亮的黑色。
这是结果
此致
LinearGradient 坐标不是相对的,它们以 canvas 网格的绝对值给出。
另外在你的情况下没有必要有镜像边界。
Shader shader = new LinearGradient(0, 0, 0, dummyHeight, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);
我已经这样设置了我的 LinearGradient
TextPaint paintText = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paintText.setColor(Color.WHITE);
paintText.setTextSize(size);
paintText.setStyle(Paint.Style.FILL_AND_STROKE);
paintText.setShadowLayer(3f, 3f, 3f, Color.BLACK);
int pL = bitmap.getWidth() / 100;
int pT = bitmap.getHeight() / 100;
StaticLayout mTextLayout = new StaticLayout(
gagTitle,
paintText,
newCanvas.getWidth(),
Layout.Alignment.ALIGN_NORMAL,
1.0f,
0.0f,
false);
int dummyHeight = mTextLayout.getHeight();
Shader shader = new LinearGradient(0, 0, 0, (dummyHeight * 2), Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR);
Paint paint = new Paint();
paint.setShader(shader);
newCanvas.drawRect(new RectF(0, 0, bitmap.getWidth(), dummyHeight), paint);
我不知道为什么,但在生成的渐变结束时,除了透明之外,它没有那么亮的黑色。
这是结果
此致
LinearGradient 坐标不是相对的,它们以 canvas 网格的绝对值给出。
另外在你的情况下没有必要有镜像边界。
Shader shader = new LinearGradient(0, 0, 0, dummyHeight, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);