0
我设法从我的mp3文件(在SD卡上)读专辑封面,但图片是 biger比活动。我如何缩小(压缩)图片为150x150像素?专辑艺术品从MP3
我设法从我的mp3文件(在SD卡上)读专辑封面,但图片是 biger比活动。我如何缩小(压缩)图片为150x150像素?专辑艺术品从MP3
您可以使用 “fitXY” 以缩放的ImageView:
<ImageView android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitXY" />
您可以通过编程设定的ImageView的来源。
下面这段代码就可以了;)
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;
}
可以使用位图的createScaledBitmap()。 –
谢谢,这个解决方案最适合我的需求。 – sekula87
欢迎我的朋友.. –