lzan13 / mlimageviewdemo Goto Github PK
View Code? Open in Web Editor NEW自定义图片类,实现圆角,圆形,按下效果等
自定义图片类,实现圆角,圆形,按下效果等
当没有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);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.