As the title implies, I\'m trying to get the user of my Android app to select an image from his device (done), I then want to scale the image down (done), compress/convert the i
Try this to convert bitmap into png:
bitmap.compress(Bitmap.CompressFormat.PNG, quality, outStream);
Check method's documentation.
You can directly convert bitmap to Base64. Use this for encoding and decoding from and to Base64.
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);
}