Bitmap.compress Call Not Returning - and NO Exception

On Android, I sometimes do the following with an image.

It never goes past the line of bitmapPicture.compress - it seems to just sit and hang.

The line above where I get the number of bytes returns 40,000.

I never see compression or any other result after "compression".

try {

    final int COMPRESSION_QUALITY = 100;
    String encodedImage;
    ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
    Log.e("Error","compress" + bitmapPicture.getByteCount());

    bitmapPicture.compress(Bitmap.CompressFormat.PNG,
                    COMPRESSION_QUALITY, byteArrayBitmapStream);
    Log.e("Error","compress done");
    byte[] b = byteArrayBitmapStream.toByteArray();
    Log.e("Error","bytear");
    encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

    Log.e("Error","JSONDATA encodedImage Returned");
    return encodedImage;

} catch (Exception e) {

    ErrorLogger.AddError(e.getMessage(), 199);
    Log.e("Error","JSONDATA Error"+e.getMessage());
    return null;
}
+4
source share
2 answers

Try to call

bitmapPicture.setConfig(Bitmap.Config.ARGB_8888);

before compression. Otherwise, can you provide a little more? Can we see where you declare / upload a bitmap?

0
source

Try using this code:

Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(b.toByteArray()));
Log.e("Compressed dimensions", decoded.getWidth()+" "+decoded.getHeight());
0
source

Source: https://habr.com/ru/post/1546233/


All Articles