Skip to content

Instantly share code, notes, and snippets.

@WrathChaos
Created June 23, 2020 13:38
Show Gist options
  • Save WrathChaos/d5e05926681c553eb54b44e01485562d to your computer and use it in GitHub Desktop.
Save WrathChaos/d5e05926681c553eb54b44e01485562d to your computer and use it in GitHub Desktop.
Android Kotlin, How to convert Bitmap to File? Article: https://freakycoder.com/android-notes-72-how-to-convert-bitmap-to-uri-e535391ebdac
fun convertBitmapToFile(context: Context, bitmap: Bitmap): Uri{  
  val file = File(Environment.getExternalStorageDirectory().toString() + File.separator + fileNameToSave)
  file.createNewFile()
  // Convert bitmap to byte array
  val baos = ByteArrayOutputStream()
  bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos) // It can be also saved it as JPEG
  val bitmapdata = baos.toByteArray()
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment