Options opt = new Options();
opt.inJustDecodeBounds = true;BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
int imageWidth = opt.outWidth;
int imageHeight = opt.outHeight;
Display dp = getWindowManager().getDefaultDisplay();
int screenWidth = dp.getWidth();
int screenHeight = dp.getHeight();
int scale = 1;
int scaleWidth = imageWidth / screenWidth;
int scaleHeight = imageHeight / screenHeight;
if(scaleWidth >= scaleHeight && scaleWidth >= 1){
scale = scaleWidth;
}
else if(scaleWidth < scaleHeight && scaleHeight >= 1){
scale = scaleHeight;
}
opt.inSampleSize = scale;
opt.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(bm);