Last active
October 7, 2023 10:50
-
-
Save ruthwikkk/e09519595b319b055912482980287293 to your computer and use it in GitHub Desktop.
Create base custom view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlurSurfaceView: View { | |
private var canvas: Canvas? = null | |
private lateinit var bitmap: Bitmap | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) | |
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { | |
super.onSizeChanged(w, h, oldw, oldh) | |
init(measuredWidth, measuredHeight) | |
} | |
private fun init(measuredWidth: Int, measuredHeight: Int) { | |
bitmap = Bitmap.createBitmap( | |
measuredWidth, | |
measuredHeight, | |
Bitmap.Config.ARGB_8888 | |
) | |
canvas = Canvas(bitmap) | |
} | |
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
canvas.save() | |
canvas.drawBitmap(bitmap, 0f, 0f, null) | |
canvas.restore() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment