Skip to content

Instantly share code, notes, and snippets.

@pjwelcome
Created December 15, 2018 07:22
Show Gist options
  • Save pjwelcome/a9eba19654e8a9353507cca447b5caee to your computer and use it in GitHub Desktop.
Save pjwelcome/a9eba19654e8a9353507cca447b5caee to your computer and use it in GitHub Desktop.
private fun getBytesFromBitmap(bitmap: Bitmap): ByteArray {
val stream = ByteArrayOutputStream()
bitmap.compress(CompressFormat.JPEG, 70, stream)
return stream.toByteArray()
}
val bitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, contentURI)
Toast.makeText(this@MainActivity, "Image Saved!", Toast.LENGTH_SHORT).show()
imageView.setImageBitmap(bitmap)
val imgString = Base64.encodeToString(getBytesFromBitmap(bitmap),Base64.NO_WRAP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment