public void click(View v){
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds=true;//inJustDecodeBounds属性
//Bitmap bm =
BitmapFactory.decodeFile("sdcard/dog.jpg",opt);
//获取图片宽高
int width = opt.outWidth;
int height = opt.outHeight;
//获取屏幕宽高
Display dp = getWindowManager().getDefaultDisplay();
int screenwidth = dp.getWidth();
int screenheight = dp.getHeight();
//计算比例
int scale=1;
int scalewidth = width/screenwidth;
int scaleheight = height/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);
System.out.println("············"+scale);
iv.setImageBitmap(bm);
}
android中 利用缩放加载本地大图片
最新推荐文章于 2021-05-29 02:17:31 发布