Because not converting to String using encoding Base64, the main reason is that you would retain data integrity when converting back to Bitmap.
I have an app that sends images to a database ...
Because you do not save the path of the image, I consider it more practical than saving the encoded image in a database registry.
To convert an Image ( bitmap
) to String
:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mybitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imagen = stream.toByteArray();
String imagenString = Base64.encode(imagen, Base64.DEFAULT);
If you do not want to code (not recommended, the ideal should be using enconding Base64), simply:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mybitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imagen = stream.toByteArray();
String imagenString = new String(imagen);