How to compose multiple shapes and add embossing?

The goal is to create a composite shape and add an embossing effect. I can successfully create the form as shown below.

    woodPaint = new Paint();
    woodPaint.setAntiAlias(true);
    woodBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.wood);
    woodShader = new BitmapShader(woodBitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    woodPaint.setShader(woodShader);

    ...

    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawCircle(handleX, radius, radius, woodPaint);
        canvas.drawRoundRect(baseRectF, 25, 25, woodPaint);

        super.onDraw(canvas);
    }

      

Picture:
51stepb.png

Then I add the EmbossMaskFilter

    paintEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.1f, 8f, 5f);
    woodPaint.setMaskFilter(paintEmboss);

      

Picture:
BmRjeY1.png

As you can see, the embossing mask is applied to the two shapes separately. How can I compose the shapes together and apply embossing to the entire object? I've tried setting the xfer mode to some sort of porter duff scent, but that doesn't affect the embossing mask being applied to each mold separately.

Thanks for any help!

Edit: As shown by Orabig, you have to draw one path with the paint on which you have set the embossing filter. NOTE. The setMaskFilter () method is one of several methods that do not work when hardware acceleration is enabled. I solved the problem I was facing with a phone running jelly bean by disabling hardware acceleration for that activity. You can turn off hardware acceleration at any level you choose:

  • Application
  • Activity
  • Window
  • View

Hooray!

+3


source to share


1 answer


Well, you only need one embossing effect, so you have to make one shape.

So, you have to use the Canvas.drawPath () method.



You just need to define a Path object using the following methods: Path definition steps Start by defining three RectF objects that will constrain the rectangles of the leftmost round (imagine the circle behind it), the rightmost and sliding: boxes definitions You may have to do some extra math to figure out the correct ones corners for use in box2 (they depend on the corresponding size of the circle and the whole rectangle)

Good luck!

+4


source







All Articles