Code Monkey home page Code Monkey logo

mlimageviewdemo's Issues

边框画不完整

当没有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);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.