圖片等比例壓縮

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

這樣就解決了微信頭像過大的問題
發佈了33 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章