Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created January 29, 2019 11:15
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 DawnImpulse/9012d12e678ac1cdd7d661950ca5d317 to your computer and use it in GitHub Desktop.
Save DawnImpulse/9012d12e678ac1cdd7d661950ca5d317 to your computer and use it in GitHub Desktop.
Save bitmap in internal storage
fun storeImage(image: Bitmap): Uri? {
var pictureFile: File = File(Environment.getExternalStorageDirectory().path + "/Folder")
val timeStamp = SimpleDateFormat("yyyy-MM-dd_HHmm").format(Date())
val name = "$timeStamp.jpg"
pictureFile = File(pictureFile.path + File.separator + name)
try {
val fos = FileOutputStream(pictureFile)
image.compress(Bitmap.CompressFormat.JPEG, 90, fos)
fos.close()
return pictureFile.toUri()
} catch (e: Exception) {
e.printStackTrace()
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment