protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile("sdcard/girl.jpg", options);
int imageWidth = options.outWidth;
int imageHeight = options.outHeight;
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
int scaleWidth = imageWidth / screenWidth;
int scaleHeight = imageHeight / screenHeight;
int scale = 1;
if (scaleWidth >= scaleHeight && scaleWidth > 0){
scale=scaleWidth;
}else if(scaleWidth<scaleHeight && scaleHeight>0){
scale=scaleHeight;
}
options.inSampleSize=scale;
options.inJustDecodeBounds=false;
Bitmap bm=BitmapFactory.decodeFile("sdcard/girl.jpg",options);
ImageView iv= (ImageView) findViewById(R.id.iv1);
iv.setImageBitmap(bm);
}