public void load(View view){
//圖片太大會導致內存溢出
//Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.big);
//創建一個配置參數
BitmapFactory.Options opts = new Options();
opts.inJustDecodeBounds = true;//不真實解析位圖,只是解析位圖的寬高信息
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.big, opts);
int width = opts.outWidth;
int height = opts.outHeight;
System.out.println("圖片的寬度:"+width);
System.out.println("圖片的高度:"+height);
int scale = 1;
//計算縮放的比例
int scaleX = width/screenWidth;
int scaleY = height/screenHeight;
if(scaleX>scaleY && scaleY>=1){
scale = scaleX;
}else if(scaleX<scaleY && scaleX>=1){
scale = scaleY;
}
opts.inSampleSize = scale;
opts.inJustDecodeBounds = false;//設置好了寬高后,真實解析位圖
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.big, opts);
iv_show.setImageBitmap(bitmap);
}免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。