简体   繁体   English

尝试使用canvas.clipPath在画布上绘制

[英]Trying to draw on canvas using canvas.clipPath

I am trying to draw circle on darken background, trying to achive smth like this - 我试图在深色背景上画圆,试图达到这样的水平- 在此处输入图片说明 This actually worked on my Samsung s4 and Samsung tab 3, but won't work on s2 and some emulator (all sorrounding viewgroup is darken, and inside oval too, seems like it does not see my circleSelectionPath). 这实际上适用于我的Samsung s4和Samsung选项卡3,但不适用于s2和某些模拟器(所有环绕的视图组均变暗,并且在椭圆形内部也似乎看不到我的circleSelectionPath)。 Help me please to find the way to make it work on every device 请帮助我找到使它在每台设备上均可使用的方法

    final Paint paint = new Paint();
    paint.setColor(Color.parseColor("#77000000"));

        Path circleSelectionPath = new Path();
        mRectF.set(l, t, r, b);
        circleSelectionPath.addOval(mRectF, Path.Direction.CW);
        canvas.clipPath(circleSelectionPath, Region.Op.XOR);
        canvas.drawRect(bitmapRect.left, bitmapRect.top, bitmapRect.right, bitmapRect.bottom, paint );
        canvas.restore();

bitmapRect contains my viewgroup dimens (for example : 0,0, 500,500) bitmapRect包含我的视图组变暗(例如:0,0,500,500)

Got it. 得到它了。 Android has a bug with canvas.clipRect, they have optimized it, but on some android apis it simple don't work after optimization ) I found an issue. Android的canvas.clipRect有一个错误,他们已经对其进行了优化,但是在某些android api上,简单地在优化后无法正常工作),我发现了一个问题。

So fix - disable hrdware acceleration for this view 所以修复-为此视图禁用Hrdware加速

    (Build.VERSION.SDK_INT <= 19 && mCropShape == CropImageView.CropShape.OVAL) {
        //TURN off hardware acceleration
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM