Created
November 27, 2015 22:31
-
-
Save elcioabrahao/17472627eb6f2817eded to your computer and use it in GitHub Desktop.
Classe utilitária para conversão de imagem bitmap em base 64 e vice versa.
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
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.util.Base64; | |
import android.util.Log; | |
import java.io.ByteArrayOutputStream; | |
/** | |
* Created by elcio on 27/11/15. | |
*/ | |
public class Base64Util { | |
public static String encodeTobase64(Bitmap image) | |
{ | |
Bitmap immagex=image; | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos); | |
byte[] b = baos.toByteArray(); | |
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT); | |
Log.e("LOOK", imageEncoded); | |
return imageEncoded; | |
} | |
public static Bitmap decodeBase64(String input) | |
{ | |
byte[] decodedByte = Base64.decode(input, 0); | |
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment