-
-
Save mistrydarshan99/2e4c89b3c5e5aad4a6b7 to your computer and use it in GitHub Desktop.
Base64Util
This file contains hidden or 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
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