android 通过拍照和获取图库的图片然后 压缩给H5回回调显示的时候,大图片压缩的太慢了,
需要4、5秒才可以时间都卡在压缩那里了,
想把选择的图片压缩在1M之内,方法是这样写的,但是感觉不太对,压缩很慢,
这是部分代码
String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
int imageLength = baos.toByteArray().length / (1024 * 1024);
if(imageLength>1){
imageLength=imageLength/100;
bitmap.compress(Bitmap.CompressFormat.PNG,imageLength,baos);
}
bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
baos.flush();
baos.close();
byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
求正确将bitmap压缩在1M之内的方法,谢谢,