Skip to content

Instantly share code, notes, and snippets.

@sprejjs
Created July 26, 2017 12:05
Show Gist options
  • Save sprejjs/cdc0b2c9f96d680cb22c5a593048871f to your computer and use it in GitHub Desktop.
Save sprejjs/cdc0b2c9f96d680cb22c5a593048871f to your computer and use it in GitHub Desktop.
private static String bitmapToString(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
return Base64.encodeToString(b, Base64.DEFAULT);
}
private static Bitmap stringToBitmap(String encodedString) {
try {
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
} catch (Exception e) {
e.getMessage();
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment