標籤:
public Bitmap inBitmap 如果設定,解碼選項“對象的方法,採取將嘗試重用這個位元影像載入內容時。public int inDensity 使用的位元影像的象素密度。public boolean inDither 如果抖動是真實的,解碼器將嘗試到抖動的解碼映像。public boolean inInputShareable 此欄位一起選擇inPurgeable。public boolean inJustDecodeBounds 如果設定為true,解碼器將返回null(位元影像),但輸出...public boolean inMutable 如果設定,解碼方法總是返回一個可變的位元影像,而不是一個一成不變的。public boolean inPreferQualityOverSpeed 如果inPreferQualityOverSpeed??設定為true,解碼器將嘗試解碼重建映像以較高的品質,甚至不惜犧牲的解碼速度。public Bitmap.Config inPreferredConfig 如果非空,這個內部配置解碼器將嘗試解碼。public boolean inPurgeable 如果設定為true,則產生的位元影像將分配給它的像素,這樣它們可以被清除,如果系統需要回收記憶體。public int inSampleSize 如果設定為> 1的值,要求的解碼器,以進行子採樣的原始映像,返回一個較小的映像,以節省記憶體。public boolean inScaled 當設定了這個標誌,如果夏季風和inTargetDensity不為0,位元影像將進行調整,以符合inTargetDensity時載入,而不是依賴它每次被畫到畫布上的圖形系統結垢。public int inScreenDensity 正在被使用的實際的螢幕的像素密度。public int inTargetDensity 目的地的像素密度的這個位元影像將被吸引到。public byte[] inTempStorage 溫度儲存用於解碼。public boolean mCancel 表明,取消已經對這個對象調用的標誌。public int outHeight 位元影像高度,設定獨立的狀態inJustDecodeBounds。public String outMimeType 如果知道,這個字串解碼後的映像的mime類型設定為。public int outWidth 位元影像的寬度,設定獨立的狀態inJustDecodeBounds。
inJustDecodeBounds設為true,BitmapFactory.decodeFile(String path, Options opt)並不會真的返回一個Bitmap給你,它僅僅會把它的寬,高取回來給你,就不會佔用太多的記憶體。
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(path, options); /* 這裡返回的bmp是null */
寬和高:options.outWidth 和 options.outHeight
擷取圖片指定大小的縮圖:
/* 計算得到圖片的高度 */ /* 這裡需要主意,如果你需要更高的精度來保證圖片不變形的話,需要自己進行一下數學運算 */ int height = options.outHeight * 200 / options.outWidth; options.outWidth = 200; options.outHeight = height; /* 這樣才能真正的返回一個Bitmap給你 */ options.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeFile(path, options); image.setImageBitmap(bmp);
要節約記憶體,還需要用到BitmapFactory.Options這個類裡的 inSampleSize 這個成員變數:
inSampleSize = options.outWidth / 200; 另外,為了節約記憶體我們還可以使用下面的幾個欄位: options.inPreferredConfig = Bitmap.Config.ARGB_4444; // 預設是Bitmap.Config.ARGB_8888 /* 下面兩個欄位需要組合使用 */ options.inPurgeable = true; options.inInputShareable = true;
Android BitmapFactory.Options