將大分辨率的圖片經過縮放顯示在手機上

                //取得圖片的分辨率
                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);
相關文章
相關標籤/搜索