Skip to content

Instantly share code, notes, and snippets.

@elcioabrahao
Created November 27, 2015 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elcioabrahao/17472627eb6f2817eded to your computer and use it in GitHub Desktop.
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.
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