繁体   English   中英

调用Bitmap.compress不会返回 - 并且没有异常

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

在Android上,我有时会使用图像执行以下操作。

它永远不会超过bitmapPicture.compress行 - 它似乎只是坐在那里挂起。

我得到字节数的上面的行返回40000。

我从来没有看到压缩完成,或'压缩'后的任何其他输出。

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

试着打电话

bitmapPicture.setConfig(Bitmap.Config.ARGB_8888);

在压缩之前。 否则,你能提供多一点吗? 我们可以看到您声明/加载位图的位置吗?

尝试使用此代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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