Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在Android9.0上运行demo 刚打开没问题,按home键之后 再进入全都显示方形图片了 #9

Open
niujiaqi opened this issue Dec 20, 2018 · 7 comments

Comments

@niujiaqi
Copy link

在Android9.0上运行demo 刚打开没问题,按home键之后 再进入全都显示方形图片了
image

@neugaojin
Copy link

加一行 srcPath.reset();就可以了
如果minSdkVersion>=19,直接使用第二种xfermode就可以

@Sincerly
Copy link

srcPath.reset();
没有这个方法啊 srcPath.reset();

@Sincerly
Copy link

换个CircleImageView就好了 - -

@tankman1016
Copy link

Android 9.0 显示有问题 有时候方形 有时候圆形

@niujiaqi
Copy link
Author

Android 9.0 显示有问题 有时候方形 有时候圆形

@OverRide
protected void onDraw(Canvas canvas) {
// 使用图形混合模式来显示指定区域的图片
canvas.saveLayer(srcRectF, null, Canvas.ALL_SAVE_FLAG);
if (!isCoverSrc) {
float sx = 1.0f * (width - 2 * borderWidth - 2 * innerBorderWidth) / width;
float sy = 1.0f * (height - 2 * borderWidth - 2 * innerBorderWidth) / height;
// 缩小画布,使图片内容不被border、padding覆盖
canvas.scale(sx, sy, width / 2.0f, height / 2.0f);
}
super.onDraw(canvas);
paint.reset();
path.reset();
if (isCircle) {
path.addCircle(width / 2.0f, height / 2.0f, radius, Path.Direction.CCW);
} else {
path.addRoundRect(srcRectF, srcRadii, Path.Direction.CCW);
}

    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setXfermode(xfermode);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
        canvas.drawPath(path, paint);
    } else {
        srcPath.reset();
        srcPath.addRect(srcRectF, Path.Direction.CCW);
        // 计算tempPath和path的差集
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            srcPath.op(path, Path.Op.DIFFERENCE);
        }
        canvas.drawPath(srcPath, paint);
    }
    paint.setXfermode(null);

    // 绘制遮罩
    if (maskColor != 0) {
        paint.setColor(maskColor);
        canvas.drawPath(path, paint);
    }
    // 恢复画布
    canvas.restore();
    // 绘制边框
    drawBorders(canvas);
}

修改成这样就好了

@tankman1016
Copy link

Android 9.0 显示有问题 有时候方形 有时候圆形

@OverRide
protected void onDraw(Canvas canvas) {
// 使用图形混合模式来显示指定区域的图片
canvas.saveLayer(srcRectF, null, Canvas.ALL_SAVE_FLAG);
if (!isCoverSrc) {
float sx = 1.0f * (width - 2 * borderWidth - 2 * innerBorderWidth) / width;
float sy = 1.0f * (height - 2 * borderWidth - 2 * innerBorderWidth) / height;
// 缩小画布,使图片内容不被border、padding覆盖
canvas.scale(sx, sy, width / 2.0f, height / 2.0f);
}
super.onDraw(canvas);
paint.reset();
path.reset();
if (isCircle) {
path.addCircle(width / 2.0f, height / 2.0f, radius, Path.Direction.CCW);
} else {
path.addRoundRect(srcRectF, srcRadii, Path.Direction.CCW);
}

    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setXfermode(xfermode);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
        canvas.drawPath(path, paint);
    } else {
        srcPath.reset();
        srcPath.addRect(srcRectF, Path.Direction.CCW);
        // 计算tempPath和path的差集
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            srcPath.op(path, Path.Op.DIFFERENCE);
        }
        canvas.drawPath(srcPath, paint);
    }
    paint.setXfermode(null);

    // 绘制遮罩
    if (maskColor != 0) {
        paint.setColor(maskColor);
        canvas.drawPath(path, paint);
    }
    // 恢复画布
    canvas.restore();
    // 绘制边框
    drawBorders(canvas);
}

修改成这样就好了

谢谢,已解决!正确答案

@fwcjszyss
Copy link

不知道怎么改, 新人一枚,谁有改好的,可否将改好的发邮件给我,在此谢过了 [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants