如何反转遮罩?

问题描述 投票:0回答:1

我正在尝试使用以下代码反转图像蒙版位图

    static final PorterDuffXfermode eraseMode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);

public void invertSelection() {
    Bitmap inverted = Bitmap.createBitmap(imageBitmap.getWidth(), imageBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    if (!annotationBitmap.sameAs(inverted)) {
        Canvas canvas = new Canvas(inverted);
        paint.setColor(Color.RED);
        canvas.drawPaint(paint);
        paint.setXfermode(eraseMode);
        canvas.drawBitmap(annotationBitmap, 0,0,paint);
        annotationBitmap = inverted;
        undoStack.push(annotationBitmap.copy(annotationBitmap.getConfig(), true));
        invalidate();
    }
}

调用此函数后,我将不再能够在annotationBitmap上进行绘制。

我在这里做错了什么?

android canvas bitmap android-custom-view paint
1个回答
1
投票

我认为您应该阅读此beautiful article at medium而且我不确定,但是我想如果您将PorterDuff.Mode.CLEAR更改为PorterDuff.Mode.DST_OUT您的问题会解决

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.