将大分辨率的图片通过缩放显示在手机上

                //取得图片的分辨率
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeResource(getResources(), R.drawable.son35,options);
                int imgHeight = options.outHeight;
                int imgWidth = options.outWidth;
                //取得手机系统的屏幕分辨率
                WindowManager manager = getWindowManager();
                Point point = new Point();
                manager.getDefaultDisplay().getSize(point);
                manager.getDefaultDisplay().getSize(point);
                int screenHeight = point.y;
                int screenWidth = point.x;
                //计算宽和高的缩放比
                int scaleHeight = imgHeight / screenHeight;
                int scaleWidth = imgWidth / screenWidth;
                int size = scaleHeight>=scaleWidth?scaleHeight:scaleWidth;
                options.inSampleSize = size;
                //解析图片
                options.inJustDecodeBounds = false;
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.son35,options);
                iv.setImageBitmap(bitmap);

 

posted @ 2016-07-18 20:41  一路向北中  阅读(347)  评论(0)    收藏  举报