绘制透明视图的一部分会将区域变为黑色

时间:2015-12-11 15:17:27

标签: android android-layout android-canvas android-custom-view android-bitmap

我有一个活动B,活动A从B打开。在活动B中有一个imageView,它保存活动A的快照(位图)。我试图绘制这个快照的一部分,使其透明,以便我可以查看此快照下面的活动A的其他视图。但是当我扩展imageview并使用onDraw中的Color.Transparent绘制它时,预期的区域变黑。我在这做错了什么?我在SO上遇到过类似的问题,但没有任何效果。

P.S。 ' B'是第一个活动,' A'从' B'

开始

编辑:快照imageview有高程,下面有视图。

'活动B','活动A,快照在其他视图之上' ,活动A与油漆

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);
}
}

0 个答案:

没有答案