1:网上很多decodeFile的是对本地的图片进行等比压缩加载 不能加载网络图片等比压缩
实验了很多次前后返回都是Null
2:对网络图片等比压缩
首先要获取到网络图片生成的bitmap
URL url = new URL(img_url);
URLConnection connection = url.openConnection();
in = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
然后等比压缩
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidht = ((float) w / width);
float scaleHeight = ((float) h / height);
matrix.postScale(scaleWidht, scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
return newbmp;
}
这样就解决了微信头像过大的问题