MLImageViewDemo icon indicating copy to clipboard operation
MLImageViewDemo copied to clipboard

边框画不完整

Open sing1 opened this issue 8 years ago • 2 comments

当没有margin的时候你的边框会出现问题

这样画就可以了

private void drawBorder(Canvas canvas){
    if(borderWidth > 0){
        borderPath.reset();
        final int width = getWidth();
        final int height = getHeight();

        if (shapeType == 0) {
            final float halfBorderWidth = borderWidth * 0.5f;
            final float cx = width * 0.5f;
            final float cy = height * 0.5f;
            final float radius = Math.min(width, height) * 0.5f;
            borderPath.addCircle(cx, cy, radius - halfBorderWidth, Path.Direction.CW);
        } else {// 当ShapeType = 1 时 图片为圆角矩形
            final float halfBorderWidth = borderWidth * 0.35f;//乘以0.5会导致border在圆角处不能包裹原图
//                leftTopRadius = Math.min(leftTopRadius, Math.min(width, height) * 0.5f);
//                leftBottomRadius = Math.min(leftBottomRadius, Math.min(width, height) * 0.5f);
//                rightTopRadius = Math.min(rightTopRadius, Math.min(width, height) * 0.5f);
//                rightBottomRadius = Math.min(rightBottomRadius, Math.min(width, height) * 0.5f);
            RectF rect = new RectF(halfBorderWidth, halfBorderWidth, width - halfBorderWidth, height - halfBorderWidth);
            borderPath.addRoundRect(rect,
                        new float[]{radius, radius, radius, radius,
                                radius, radius, radius, radius},
                        Path.Direction.CW);
        }

        Paint paint = new Paint();
        paint.setStrokeWidth(borderWidth);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(borderColor);
        paint.setAntiAlias(true);
        canvas.drawPath(borderPath, paint);
    }
}

sing1 avatar Dec 27 '16 07:12 sing1

这个当时没有考虑这么细,感谢提醒

lzan13 avatar Dec 27 '16 09:12 lzan13

https://github.com/Sing1/Util/blob/master/explain/RoundImageView.md 已经盗走 ^-^

sing1 avatar Dec 27 '16 09:12 sing1