{
"title":"how to begain Android?",
"content":"do it, do it, do it",
"picture":"http://192.168.0.1/pic/2015/09/02/share_thumb.jpg"
...
...
}
int options = 100;
ByteArrayOutputStream outputs = new ByteArrayOutputStream();
oBitmap.compress(Bitmap.CompressFormat.JPEG, options, outputs); //
while ( outputs.toByteArray().length / 1024 > 32 ) {
outputs.reset();
oBitmap.compress(Bitmap.CompressFormat.JPEG, options, outputs);
options -= 10 ;
}
ByteArrayInputStream inputs = new ByteArrayInputStream(outputs.toByteArray());
Bitmap bitmap = BitmapFactory.decodeStream(inputs, null , null );
BitmapFactory.Options newOpts = new BitmapFactory.Options(); newOpts.inSampleSize = 2; bitmap = BitmapFactory.decodeFile(picturePath, newOpts);
public static byte[] WeChatBitmapToByteArray(Bitmap bmp, boolean needRecycle) {
// 首先进行一次大范围的压缩
ByteArrayOutputStream output = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, output);
float zoom = (float)Math.sqrt(32 * 1024 / (float)output.toByteArray().length); //获取缩放比例
// 设置矩阵数据
Matrix matrix = new Matrix();
matrix.setScale(zoom, zoom);
// 根据矩阵数据进行新bitmap的创建
Bitmap resultBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
output.reset();
resultBitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
// 如果进行了上面的压缩后,依旧大于32K,就进行小范围的微调压缩
while(output.toByteArray().length > 32 * 1024){
matrix.setScale(0.9f, 0.9f);//每次缩小 1/10
resultBitmap = Bitmap.createBitmap(
resultBitmap, 0, 0,
resultBitmap.getWidth(), resultBitmap.getHeight(), matrix,true);
output.reset();
resultBitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
}
return result;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有