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;
}
這樣就解決了微信頭像過大的問題