2014年4月28日 星期一

Android 4.4 Decode Bitmap From InputStream Return NULL

在 Android 4.4 時,如果 BitmapFactory 重複使用同一個 InputStream 去進行 decode 會回傳 null。
就算第一次只是拿去用 inJustDecodeBounds 也一樣。
每次要使用前都要做 is.reset();



BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, opts);
...
opts.inSampleSize = ...
opts.inJustDecodeBounds = false;
...
is.reset(); //XXX Android 4.4 KitKat, Important! Without this, bmp will return null.
Bitmap bmp = BitmapFactory.decodeStream(is, null, opts);
view raw gistfile1.java hosted with ❤ by GitHub

沒有留言:

張貼留言