Android Paint EmbossMaskFilter conflicting with setShadowLayer

540 views Asked by At

It looks like the mPaint.setShadowLayer() interferes with the mPaint.EmbossMaskFilter() directive. I cannot have both set for my paint, as there is nothing is drawn on the canvas otherwise.

 mPaintRing = new Paint();
 mPaintRing.setFlags(Paint.ANTI_ALIAS_FLAG);
 mPaintRing.setColor(colorGold);
 mPaintRing.setDither(true);
 mPaintRing.setShadowLayer(3,0,15,colorBackShadow);
 mPaintRing.setStyle(Paint.Style.STROKE);
 mPaintRing.setMaskFilter(new EmbossMaskFilter(new float[]{0, 1, 1},0.7f, 6.0f, 7.5f));

Is that an expected behavior, a bug, or am I missing something? I'm building for M using the appcompat 7.23.14 with minSDK 11.

2

There are 2 answers

0
halxinate On

The workaround is to use another drawable with the same outer contour shape and location with the paint having the shadow layer but no emboss, and draw it prior to drawing the embossed one. To avoid possible anti-aliasing artifacts that paint should have a transparent color attrib.

1
Muhammad Sulaiman On

Try this code for applying both EmbossMaskFilter and setShadowLayer property on Paint. This work for perfectly.

mPaintRing.setShadowLayer(3,0,15,Color.Black);
mPaintRing.setMaskFilter(null);
canvas.drawText(mPaintRing.getText, 0, 0, mPaintRing);

mPaintRing.clearShadowLayer();
mPaintRing.setMaskFilter(new EmbossMaskFilter(new float[]{0, 1, 1},0.7f, 6.0f, 7.5f));
canvas.drawTextOnPath(mPaintRing.getText, 0, 0, mPaintRing);

if Still their is some problem ask here or show me your whole code i will be their for help.