Dimezis / BlurView

Dynamic iOS-like blur of underlying Views for Android
Apache License 2.0
3.48k stars 331 forks source link

About BlurView how to set fillet? #192

Closed wardenlzr closed 1 year ago

wardenlzr commented 1 year ago

blurOverlayColorOnly one property can be configured

Dimezis commented 1 year ago

Sorry, I'm not sure what you mean. Could you elaborate?

wardenlzr commented 1 year ago

Sorry,My English is not good. I think the answer is this Create a rounded drawable, as usual, set it as a background. And do blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND); blurView.setClipToOutline(true);

wardenlzr commented 1 year ago

But final Drawable windowBackground = getWindow().getDecorView().getBackground(); Log.i(TAG, "windowBackground." + windowBackground); RoundDrawable roundDrawable = new RoundDrawable(getResources(), drawable2Bitmap(windowBackground)); roundDrawable.setRadius(30f); binding.bv.setupWith(((ViewGroup) getWindow().getDecorView())) .setFrameClearDrawable(roundDrawable);

private Bitmap drawable2Bitmap(Drawable drawable) { if (drawable == null) { return null; }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap.Config config =
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565;
        Bitmap bitmap;
        //颜色Drawable
        if (drawable instanceof ColorDrawable) {
            //宽为2, 高为2 ??
            bitmap = Bitmap.createBitmap(2, 2, config);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), config);
        }
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        //将 drawable 的内容绘制到 bitmap的canvas 上面去.
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

I set these, but the fillet does not take effect

wardenlzr commented 1 year ago

final Drawable windowBackground = getWindow().getDecorView().getBackground(); Log.i(TAG, "windowBackground." + windowBackground); // RoundDrawable roundDrawable = new RoundDrawable(getResources(), drawable2Bitmap(windowBackground)); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ex_bg); Drawable roundDrawable = new RoundDrawable(bitmap); binding.bv.setupWith(((ViewGroup) getWindow().getDecorView())) .setFrameClearDrawable(roundDrawable); binding.iv.setImageDrawable(roundDrawable);

I'm sure roundDrawable is OK

Dimezis commented 1 year ago

I still don't understand. Is the problem that you can't set rounded corners?

blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
blurView.setClipToOutline(true);

Should do the job with a proper rounded corner Drawable.

Or is the problem that setFrameClearDrawable doesn't work with this drawable? (Why is it rounded though?)

Some screenshots of expected and actual results might be helpful

wardenlzr commented 1 year ago

image How to get a round corner BlurView?

Dimezis commented 1 year ago
blurView.setBackgroundDrawable(roundDrawable);
blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
blurView.setClipToOutline(true);
Dimezis commented 1 year ago

Did that solve your issue?

wardenlzr commented 1 year ago

yes thanks