2012-05-21 57 views
0

我設法從我的mp3文件(在SD卡上)讀專輯封面,但圖片是 biger比活動。我如何縮小(壓縮)圖片爲150x150像素?專輯藝術品從MP3

+0

可以使用位圖的createScaledBitmap()。 –

+0

謝謝,這個解決方案最適合我的需求。 – sekula87

+0

歡迎我的朋友.. –

回答

2

您可以使用 「fitXY」 以縮放的ImageView:

<ImageView android:layout_width="150dp" 
      android:layout_height="150dp" 
      android:scaleType="fitXY" /> 

您可以通過編程設定的ImageView的來源。

0

下面這段代碼就可以了;)

public static Bitmap decodeFile(File f, boolean goodQuality){ 
     try { 
      //Decode image size 
      BitmapFactory.Options o = new BitmapFactory.Options(); 
      o.inJustDecodeBounds = true; 
      BitmapFactory.decodeStream(new FileInputStream(f),null,o); 

      //The new size we want to scale to 
      final int REQUIRED_SIZE=100; 

      //Find the correct scale value. It should be the power of 2. 
      int scale=1; 
      if(!goodQuality){ 
       while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE) 
        scale*=2; 
      } 
      //Decode with inSampleSize 
      BitmapFactory.Options o2 = new BitmapFactory.Options(); 
      o2.inSampleSize=scale; 
      return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); 
     } catch (FileNotFoundException e) {} 
     return null; 
    }