Convert a bitmap to string

1

Is there a way to convert a bitmap to string without converting it to base64 ? I have an app that sends images to a database, but I send them in base64 , and this takes up a lot of memory (based on what I've read) for that reason I need to convert bitmap to string . Thanks.

    
asked by jaron cascante Pérez 24.11.2016 в 20:07
source

1 answer

3

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);
    
answered by 24.11.2016 / 20:47
source