package com.ztone.musicplayer.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;

/**
 * 图片模糊处理
 * Created by lby on 2017/2/24.
 */

public class BlurBitmap {
    public Bitmap blur(Bitmap bitmap, int w,int h) {
        float scaleFactor = 1;
        /**
         * 这里是双重模糊手段
         * scaleFactor是将bitmap缩小至原来的 n 倍u,然后在填充的时候被拉伸 n 倍,从而模糊
         * radius是模糊半径,有FastBlur处理
         * 两者都是乘积越大,越模糊
         * */
        float radius = 20;
        if (bitmap != null) {
            scaleFactor = 18;
            radius = 8;
        }

        Log.e("test","w = " +w+ " h = "+ h / scaleFactor + "bitmap = "+bitmap);
        Bitmap overlay = Bitmap.createBitmap((int) (bitmap.getWidth() / scaleFactor),
                (int) (bitmap.getHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        canvas.scale(1 / scaleFactor, 1 / scaleFactor);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(bitmap, 0, 0, paint);

        overlay = FastBlur.doBlur(overlay, (int) radius, true);
        return overlay;
    }

}