2

I want to get an embossed bitmap created based on a Path object. The problem is that embossed effect only applies for straight edge.

I want to get a final result like this:

enter image description here

Path Object is created as follows

Path mPath= new Path();

mPath.moveTo(100, 100);
mPath.lineTo(200, 100);
mPath.lineTo(150, 150);
mPath.lineTo(200, 200);
mPath.lineTo(100, 200);
mPath.close();

Then a bitmap is created out of this path object as follows. With the embossed filter.

    piecePicture = Bitmap.createBitmap(200, 200,Bitmap.Config.ARGB_8888);

    MaskFilter mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
    Canvas gfx = new Canvas(piecePicture);


    Paint whitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    whitePaint.setColor(Color.WHITE);
    whitePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    whitePaint.setStrokeWidth(1);

    // shape image has to take
    mPath.addRect(10, 10, 195, 195, Direction.CCW);
    gfx.drawPath(mPath, whitePaint);

    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
    paint.setMaskFilter(mEmboss);   
    // draw the image on path viewBgrnd is the bitmap    
    gfx.drawBitmap(viewBgrnd, 10,10, paint);
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
pats
  • 1,273
  • 2
  • 20
  • 43

1 Answers1

1

Unfortunately the EmbossMaskFilter only works with STROKE and FILL_AND_STROKE paints. I can't point to any documentation about this but based on my experimentation those are the only cases I can get it to work.

Jared
  • 1,449
  • 2
  • 19
  • 40
  • Thanks for your response. I m stuck for months because of this. I have used FILL_AND_STROKE in my implementation. Do you mean because I have used PorterDuff and overlaid an image this is not working. How can I make this work any alternatives? – pats Mar 07 '15 at 08:15