Decrease a base64 [duplicate]

0

How do I decrease a base64 size without decreasing quality? I'm having a problem with this code because it's too big and it's not saving in the database. How to decrease?

    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    byte[] b = bytes.toByteArray();
    String encodedfile = Base64.encodeToString(b, Base64.DEFAULT);


    base64p = encodedfile;
    
asked by anonymous 26.07.2017 / 18:59

1 answer

2

Technically on the line

thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);

You are not dealing with anything in the image, just changing the format of it.

What you have to do is, before doing the conversion, is to treat the image. Using the Compressor library as an example ( link ), you can treat the image before converting to Base64 (the treatment MUST be made in the image before the conversion).

But as @Marquezani commented in your question, there is a real need to write the base64, could not, for example, save the bytes of the image or the image itself in a BLOB?

    
27.07.2017 / 15:32