<span style="font-size:18px;">Display display=getWindowManager().getDefaultDisplay();
int dh=display.getHeight();
int dw=display.getWidth();
//加载图像的尺寸而不是图像本身
BitmapFactory.Options bOptions=new BitmapFactory.Options();
bOptions.inJustDecodeBounds=true;
Bitmap bm=BitmapFactory.decodeFile(pathName, bOptions);
int height=(int)Math.ceil(bOptions.outHeight/(float)dh);
int weight=(int)Math.ceil(bOptions.outWidth/(float)dw);
//如果两个比率都大于1,那么图像的一条边将大于屏幕
if(height>1&&weight>1)
{
if(height>weight)
{
//若高度比率更大则根据它缩放
bOptions.inSampleSize=height;
}
else
{
//若宽度比率更大则根据它缩放
bOptions.inSampleSize=weight;
}
}
//对它进行真正解码
bOptions.inJustDecodeBounds=false;
bm=BitmapFactory.decodeFile(pathName, bOptions);</span>