1.高斯模糊
public void getBlur(){
long startMs = System.currentTimeMillis();
Bitmap bitmap = ((BitmapDrawable)(iv.getBackground())).getBitmap();
RenderScript script = RenderScript.create(getContext());
Allocation allocation = Allocation.createFromBitmap(script,bitmap);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(script,allocation.getElement());
blur.setInput(allocation);
for (int i=0;i<4;i++){
blur.setRadius(25);
blur.forEach(allocation);
}
allocation.copyTo(bitmap);
blur.destroy();
allocation.destroy();
script.destroy();
Log.e("TAG","getBlur: "+(System.currentTimeMillis()-startMs));
iv.setBackground(new BitmapDrawable(getResources(),bitmap));
}
2.贝塞尔曲线
package ccav.xulingyun.com.testdagger2.view;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import ccav.xulingyun.com.testdagger2.R;
/**
* Created by Cantaloupe--郓 on 2018/1/9.
* 描述:
*/
public class HalfCircleViewextends View {
PaintmHalfCirclePaint;
int mWidth;
int mHeight;
int mRadius;
PointmCenterPoint;
BitmapmBitmap;
LinearGradientmLinearGradient;
private PorterDuffXfermodemPorterDuffXfermode;
public HalfCircleView(Context context) {
this(context,null);
}
public HalfCircleView(Context context,@Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public HalfCircleView(Context context,@Nullable AttributeSet attrs,int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mHalfCirclePaint =new Paint();
mHalfCirclePaint.setAntiAlias(true);
mHalfCirclePaint.setStyle(Paint.Style.FILL);
mHalfCirclePaint.setColor(Color.YELLOW);
mCenterPoint =new Point();
mBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.bikaqiu);
mLinearGradient =new LinearGradient(mWidth/2,0,mWidth/2,mHeight,Color.CYAN,Color.GRAY, Shader.TileMode.MIRROR);
}
@Override
protected void onSizeChanged(int w,int h,int oldw,int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = getWidth();
mHeight = getHeight();
mRadius = (int) (mWidth*1.5);
mCenterPoint.x =mWidth/2;
mCenterPoint.y =mHeight-mRadius;
mPorterDuffXfermode =new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
}
@Override
protected void onDraw(Canvas canvas) {
int layerId = canvas.saveLayer(0,0,mWidth,mHeight,null, Canvas.ALL_SAVE_FLAG);
canvas.drawCircle(mCenterPoint.x,mCenterPoint.y,mRadius,mHalfCirclePaint);
mHalfCirclePaint.setXfermode(mPorterDuffXfermode);
canvas.drawBitmap(mBitmap,0,0,mHalfCirclePaint);
mHalfCirclePaint.setXfermode(null);
canvas.restoreToCount(layerId);
}
}