我正在使用BitmapFactory重置为无效标记,尽管我得到的Bitmap不是null并且是一个有效的Jpeg。我做错了什么?
logcat的:
01-15 18:54:42.141 12533-12533/com.example.carlo.regional2 E/RecyclerView: No adapter attached; skipping layout
01-15 18:55:01.531 12533-12625/com.example.carlo.regional2 E/NewPostTaskFragment: Error occurred during resize: Resetting to invalid mark
01-15 18:55:01.533 12533-12533/com.example.carlo.regional2 E/NewPostActivity: Couldn't resize bitmap in background task.
一段代码:
class LoadResizedBitmapTask extends AsyncTask<Uri, Void, Bitmap> {
private int mMaxDimension;
public LoadResizedBitmapTask(int maxDimension) {
mMaxDimension = maxDimension;
}
// Decode image in background.
@Override
protected Bitmap doInBackground(Uri... params) {
Uri uri = params[0];
//ZC
try {
InputStream stream = new BufferedInputStream(
mApplicationContext.getContentResolver().openInputStream(uri));
stream.mark(stream.available());
Bitmap bitmap = BitmapFactory.decodeStream(stream);
stream.reset();
return bitmap;
} catch (FileNotFoundException e) {
Log.e(TAG, "Can't find file to resize: " + e.getMessage());
FirebaseCrash.report(e);
} catch (IOException e) {
Log.e(TAG, "Error occurred during resize: " + e.getMessage());
FirebaseCrash.report(e);
}
答案 0 :(得分:1)
Java的流API带来了一些不可取的东西。
在这种情况下,ts
和mark()
并不总是有效,特别是对于由文件系统上的简单文件以外的其他内容支持的流。如果您想使用它们,请先致电reset()
。
后备是从markSupported()
请求新流。