Skip to content

Instantly share code, notes, and snippets.

@Vikctar
Created July 1, 2017 20:23
Show Gist options
  • Save Vikctar/135c49942f28fc2180866573eac50a67 to your computer and use it in GitHub Desktop.
Save Vikctar/135c49942f28fc2180866573eac50a67 to your computer and use it in GitHub Desktop.
convert bitmap to string
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] imageBytes = byteArrayOutputStream.toByteArray();
return "data:image/jpeg;base64," + Base64.encodeToString(imageBytes, Base64.DEFAULT);
}
@Vikctar
Copy link
Author

Vikctar commented Jul 1, 2017

I appended the raw string to the base64 one since the server was expecting the string to start like that.
You can remove it and just return a base64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment