0
好吧,所以我下載一個圖像,併發送輸入流到這個方法巫婆必須解碼一次找到圖像大小,然後計算一個比例值,然後從流中創建一個迷你版本的位圖。 ..但我得到的logcat錯誤,bitmapFactory返回null,任何人都有一個想法可能是錯誤的?BitmapFactory返回null Android
public static Bitmap getSampleBitmapFromStream(InputStream is,
int reqWidth, int reqHeight) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);
// Find the correct scale value. It should be the power of 2.
int width_tmp = options.outWidth, height_tmp = options.outHeight;
int scale = 1;
while (true) {
if (width_tmp/2 < reqWidth || height_tmp/2 < reqHeight)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// decode with inSampleSize
options.inJustDecodeBounds = false;
options.inSampleSize = scale;
return BitmapFactory.decodeStream(new FlushedInputStream(is), null, options);
}