1.关于 CV这种事,强调了很多遍,关键字,现在一步一步捋下过程,
一.拿到需求 毛玻璃效果
神马 都不要看,直接去github 官网,看看代码冗余么,好接入么,多的话直接pass,看关键字blur
二.github
开始核对需求效果,然后再看能不能接入,同样看冗余,
3.github依赖炸了
然而他的star很多,依赖不能用,那是不可能的,有很大的几率是最新版本有问题不兼容,可以找历史版本或者直接项目名百度,看看有木有人使用过这个库,看看别人走过 的 坑!
最后
https://github.com/mmin18/RealtimeBlurView 这个性能高 星多
https://github.com/nbwzlyd/realTimeBlurView2 星少 可能兼容性更高 效果差不多
第一个版本不行
compile 'com.github.mmin18:realtimeblurview:1.0.3'
public class CustomShapeBlurView extends RealtimeBlurView {
Paint mPaint;
RectF mRectF;
public CustomShapeBlurView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mRectF = new RectF();
}
/**
* Custom oval shape
*/
@Override
protected void drawBlurredBitmap(Canvas canvas, Bitmap blurredBitmap, int overlayColor) {
if (blurredBitmap != null) {
int width = getWidth();
int height = getHeight();
mRectF.right = width;
mRectF.bottom = height;
mPaint.reset();
mPaint.setAntiAlias(true);
BitmapShader shader = new BitmapShader(blurredBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.postScale(mRectF.width() / blurredBitmap.getWidth(), mRectF.height() / blurredBitmap.getHeight());
shader.setLocalMatrix(matrix);
mPaint.setShader(shader);
canvas.drawOval(mRectF, mPaint);
mPaint.reset();
mPaint.setAntiAlias(true);
mPaint.setColor(overlayColor);
RectF rectF = new RectF(0, 0, width, height);
canvas.drawRoundRect(rectF, 30, 30, mPaint);
}
}
}