Skip to content

Instantly share code, notes, and snippets.

@mistrydarshan99
Forked from vaibhav-jani/Base64ImageUtil.java
Last active August 28, 2015 10:50
Show Gist options
  • Save mistrydarshan99/2e4c89b3c5e5aad4a6b7 to your computer and use it in GitHub Desktop.
Save mistrydarshan99/2e4c89b3c5e5aad4a6b7 to your computer and use it in GitHub Desktop.
Base64Util
import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
public class Base64ImageUtil {
public static Bitmap stringToBitmap(String encodedString) {
try {
byte[] encodeByte = Base64
.decode(encodedString, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
encodeByte.length);
return bitmap;
} catch (Exception e) {
e.getMessage();
return null;
}
}
public static String bitmapToString(Bitmap bitmap) {
ByteArrayOutputStream ByteStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, ByteStream);
byte[] b = ByteStream.toByteArray();
String temp = Base64.encodeToString(b, Base64.DEFAULT);
return temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment