Skip to content

Instantly share code, notes, and snippets.

@emregoren
Last active May 29, 2020 15:00
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 emregoren/c1ccb617cd7e1918728cdfb97fdf3bcf to your computer and use it in GitHub Desktop.
Save emregoren/c1ccb617cd7e1918728cdfb97fdf3bcf to your computer and use it in GitHub Desktop.
fun encodeImage(bm: Bitmap): String? {
val baos = ByteArrayOutputStream()
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos)
val b = baos.toByteArray()
return Base64.encodeToString(b, Base64.DEFAULT)
}
fun decodeImage(bm: String, imageView: ImageView,resources: Resources) {
val imageBytes = Base64.decode(bm, Base64.DEFAULT)
val decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
val ob = BitmapDrawable(resources, decodedImage)
imageView.background=ob
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment