mmin18 / RealtimeBlurView

A realtime blurring overlay for Android (like iOS UIVisualEffectView)
Other
3.17k stars 343 forks source link

Support for circle shape blur #45

Open tmdroid opened 4 years ago

tmdroid commented 4 years ago

Hello,

It would be nice to also support blurring in a shape of circle, not only squares or rectangles.

zmunm commented 3 years ago

Same issue as me but connected PR didn't work for me

In my project, I am using Fresco and I don't have much time, so I solved it by changing to XferRoundFilter after mBlurredBitmap, but it would be nice if the library could be used independently.

zmunm commented 3 years ago

Hello. It's a good day to code

I used OutlineProvider and everything is happy now.

Attach some of the code created for databinding.


@BindingAdapter("roundOutlineRadius")
fun View.setRoundOutlineRadiusBinding(roundOutlineRadius: Float) {
    outlineProvider = object : ViewOutlineProvider() {
        override fun getOutline(view: View, outline: Outline?) {
            outline?.setRoundRect(0, 0, view.width, view.height, roundOutlineRadius)
        }
    }

    clipToOutline = true
}

@BindingAdapter("roundAsCircle")
fun View.setRoundAsCircleBinding(isCircle: Boolean) {
    if (isCircle) {
        outlineProvider = object : ViewOutlineProvider() {
            override fun getOutline(view: View, outline: Outline?) {
                val rect = Rect(0, 0, view.width, view.height)
                outline?.setRoundRect(rect, rect.width() / 2f)
            }
        }

        clipToOutline = true
    }
}
            <com.github.mmin18.widget.RealtimeBlurView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_margin="30dp"
                app:realtimeBlurRadius="5dp"
                app:realtimeOverlayColor="#4fff"
                app:roundAsCircle="@{true}"
                app:layout_constraintStart_toStartOf="@id/image"
                app:layout_constraintTop_toTopOf="@id/image" />