BitmapFactory . Options option = new Options();
option . inJustDecodeBounds = true ; //只加载图片的头信息
BitmapFactory . decodeFile(url , option);
int picWidth = option . outWidth; //获取图片宽
int picHeight = option . outHeight //获取图片高
Display display = getWindowManager() . getDefaultDisplay();
int width = display . getWidth(); //获取屏幕宽
int height = display . getHeight(); //获取屏幕高
int scaleX = picWidth / width ; //宽的比
int scaleY = picHeight / height; //高的比
if(scaleX > scaleY && scaleY>1){
option . inSampleSize= scaleX; //设置宽高比为宽
}else if(scaleX < scaleY && scaleX>1){
option . inSampleSize= scaleY; //设置宽高比为高
}
option . inJustDecodeBounds = false;
BitmapFactory . decodeFile(url , option);