Skip to content

Instantly share code, notes, and snippets.

@ruthwikkk
Last active October 7, 2023 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruthwikkk/e09519595b319b055912482980287293 to your computer and use it in GitHub Desktop.
Save ruthwikkk/e09519595b319b055912482980287293 to your computer and use it in GitHub Desktop.
Create base custom view
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