我在開發人員的網站上找到了有關加載大型位圖高效教程的文章。兩次解碼bitmapfactory有什麼用?
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
**BitmapFactory.decodeResource(res, resId, options);**
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
我的問題是什麼是解碼資源的第一次,你可以設置inSampleSize然後解碼它。