2

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.

halxinate
  • 1,509
  • 15
  • 22

2 Answers2

0

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.

halxinate
  • 1,509
  • 15
  • 22
0

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.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
  • That's in fact almost the same thing as my workaround - drawing the object twice. But in my case, I'm just defining 2 different Paints in advance. Your approach might be fine for a static drawing, but altering the paint during onDraw for an animated custom view might be too expensive. – halxinate Dec 11 '16 at 05:20