0

I am developing color splash app. in which i use finger paint.

Now i want to emboss bitmap on touch event. i have one demo here in which when i apply emboss then it draw emboss path with red color but i want to emboss behind bitmap on touch.

private Path mPath;
private MaskFilter mEmboss;

public void init(){
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(color.RED);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(20);
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
}



// on click event 
    switch (item.getItemId()) {
        case EMBOSS_MENU_ID:                        
            mPaint.setMaskFilter(mEmboss);
    }



// View Class method

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);           
    canvas.drawPath(mPath, mPaint);
    canvas.drawPath(circlePath, circlePaint);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    float x = ev.getX();
    float y = ev.getY();
    invalidate();
    return true;
}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437

1 Answers1

2

I eventually find the solution:

Use BitmapShader with same bitmap

private Path mPath;
private MaskFilter mEmboss;

public void init(){
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(color.RED);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(20);
BitmapShader fillBMPshader = new BitmapShader(bm_original, Shader.TileMode.MIRROR, Shader.TileMode.CLAMP);
mPaint.setShader(fillBMPshader);
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
}    

// onclick event 
    switch (item.getItemId()) {
        case EMBOSS_MENU_ID:                        
            mPaint.setMaskFilter(mEmboss);
    }

// View Class method

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);           
    canvas.drawPath(mPath, mPaint);
    canvas.drawPath(circlePath, circlePaint);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    float x = ev.getX();
    float y = ev.getY();
    invalidate();
    return true;
}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437