{
// 若高度比率更大,则根据它缩放
bmpFactoryOptions.inSampleSize = heightRatio;
}
else
{
// 若宽度比率更大,则根据它缩放
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
//对它进行真正的解码
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeFile(imageFilePath,
bmpFactoryOptions);
// 显示图像
imv.setImageBitmap(bmp);
上述代码需要下列layout/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>