简体   繁体   中英

call to Bitmap.compress does not return - and NO exception

On Android I sometimes do the following with an image.

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

The line above where I get the byte count returns 40000.

I never see compress done, or any other output after 'compress'.

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;
}

Try calling

bitmapPicture.setConfig(Bitmap.Config.ARGB_8888);

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

Try to use this code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM