Using zoom to load local large pictures in android

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325805331&siteId=291194637