Decrease a Base64

Asked

Viewed 2,684 times

1

How to decrease a size of a Base64 without decreasing the quality so much? I’m trying a problem in this code,because it’s too big and it’s not saving in the bank. 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;
  • James the character > is to be used to quote something in the question, not to highlight all of its text. Try to use the quote only when necessary.

  • @Thiago Do you really need to save a Base64 in the database? It can’t be a BLOB?

1 answer

2


Technically on the line

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

you are not treating anything in the image, only changing the format of it.

What you have to do is, before you do the conversion, treat the image. Using the Compressor library as an example (https://github.com/zetbaitsu/Compressor), you can treat the image before converting to Base64 (the treatment HAS to be done on the image before converting).

But as @Marquezani commented in his question, there is the real need to record Base64, n could for example record the image bytes or image itself in a BLOB?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.