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);