Skip to content

Instantly share code, notes, and snippets.

@mdavalos1993
Last active June 10, 2020 17:39
Show Gist options
  • Select an option

  • Save mdavalos1993/ce88b657fd9c4419c4b75adb3bc32659 to your computer and use it in GitHub Desktop.

Select an option

Save mdavalos1993/ce88b657fd9c4419c4b75adb3bc32659 to your computer and use it in GitHub Desktop.

Revisions

  1. mdavalos1993 revised this gist Jun 10, 2020. No changes.
  2. mdavalos1993 revised this gist Jun 10, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions ViewToBitmap.kt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    package me.marcosdavalos.util

    import android.graphics.Bitmap
    import android.graphics.Canvas
    import android.graphics.Color
    import android.view.View

    val View.toBitmap: Bitmap get(){
    val bitmap = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888)
    val canvas = Canvas(bitmap)
  3. mdavalos1993 created this gist Jun 10, 2020.
    12 changes: 12 additions & 0 deletions ViewToBitmap.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    val View.toBitmap: Bitmap get(){
    val bitmap = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888)
    val canvas = Canvas(bitmap)
    val bgDrawable = this.background
    if(bgDrawable != null){
    bgDrawable.draw(canvas)
    }else{
    canvas.drawColor(Color.BLACK)
    }
    this.draw(canvas)
    return bitmap
    }