0

I have an activity B and activity A opens from B. In the activity B there is one imageView which holds the snapshot(bitmap) of activity A. I am trying to paint a part of this snapshot to make it transparent so that I can look at the other views of activity A that are beneath this snapshot. But when I extend the imageview and paint it with Color.Transparent in onDraw, the expected area turns black. What am I doing wrong here? I have gone through similar questions on SO but nothing worked.

P.S. 'B' is first activity and 'A' opens from 'B'

Edit: snapshot imageview has elevation and there are views beneath it.

'Activity B', 'Activity A with Snapshot on top of other views' , Activity A with Paint

Activity B Activity A Paint

public class SnapShotImageView extends ImageView {
private  Bitmap bitmap;
private  Canvas temp;
private Paint mPaint;
private Path mPath;

public SnapShotImageView(Context context) {
    super(context);
    init();
}

public SnapShotImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public SnapShotImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

public SnapShotImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init();
}

private void init() {
    setWillNotDraw(false);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
    mPaint.setColor(Color.TRANSPARENT);
    mPaint.setStyle(Paint.Style.FILL);
    mPath = new Path();

}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int width = getMeasuredWidth();
    int halfWidth = width / 2;
    int height = getMeasuredHeight();

    mPath.moveTo(width, height -width);
    mPath.addArc(0, height - 3 * halfWidth, width, height - halfWidth, 0, 90);
    mPath.addArc(-halfWidth, height - width, halfWidth, height, 0, 90);
    mPath.lineTo(width, height);
    mPath.lineTo(width, height - width);
    mPath.close();
    canvas.clipPath(mPath);
    canvas.drawPath(mPath,mPaint);
}
}
Neanderthal
  • 937
  • 2
  • 9
  • 25
  • I have a similar question too. – Deepak Banka Dec 11 '15 at 15:39
  • are you trying to erase ? – HourGlass Dec 11 '15 at 16:21
  • I'm trying to make that area in black to transparent so that I could see the views beneath that image view. The image view has elevation and there are some views beneath that. – Neanderthal Dec 11 '15 at 16:27
  • 1
    @Neanderthal Here is how color.Transparent can be helpful. you can use it to make your paint object to transparent,so that the paint you draw won't be on screen. you can use Color.Transparent with PortefDuff mode to erase painted color. Clearly you can not use this other way, like you are thinking. – HourGlass Dec 11 '15 at 16:42
  • Ok. How can we achieve my desired result. Any suggestions? – Neanderthal Dec 11 '15 at 16:56
  • @HourGlass Hey Thanks. I solved the issue by changing the porterduff mode to CLEAR and changing the layer type for the view to software. – Neanderthal Dec 14 '15 at 09:06
  • good to know. if any of my comment is helpful, mark it as useful. – HourGlass Dec 14 '15 at 10:01

0 Answers0