{
// 若高度比率更大,則根據(jù)它縮放
bmpFactoryOptions.inSampleSize = heightRatio;
}
else
{
// 若寬度比率更大,則根據(jù)它縮放
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
//對(duì)它進(jìn)行真正的解碼
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeFile(imageFilePath,
bmpFactoryOptions);
// 顯示圖像
imv.setImageBitmap(bmp);
上述代碼需要下列l(wèi)ayout/main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/ReturnedImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ImageView>
</LinearLayout>