Last active
May 29, 2020 15:00
-
-
Save emregoren/c1ccb617cd7e1918728cdfb97fdf3bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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