好的,所以我下载图像并将输入流发送到此方法,女巫必须对其进行一次解码以找到图像大小,然后计算比例值,然后从流中创建位图的迷你版本....但我在logcat bitmapFactory 正在返回 null,任何人都知道可能出了什么问题?
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);
}