在我Bitmap
使用Fresco
using获取时不理解该行为ImagePipeline
。当我调试我的代码时,它正在执行onNewResultImpl
,或者onFailureImpl
当我运行应用程序时,应用程序不工作意味着它没有被调用onFailureImpl
,或者onNewResultImpl
(我正在使用Toast
并Log
在运行应用程序时检查它)。我已经看到了这个SO Question 并从中获取参考,也从Fresco's
文档中获取。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case ACTION_OPEN_GALLERY:
mImageCaptureUri = data.getData();
if (mImageCaptureUri != null) {
commentImgView.setImageURI(mImageCaptureUri);//mImageCaptureUri is working fine
try {
imageRequest = ImageRequestBuilder
.newBuilderWithSource(mImageCaptureUri)
.setRequestPriority(Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
.build();
dataSource = imagePipeline.fetchDecodedImage(imageRequest, CommentActivity.this);
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(@Nullable Bitmap bitmap) {
if (bitmap != null) {
bmp = Bitmap.createBitmap(bitmap);
Log.d("Bitmap ","after callback");
Toast.makeText(CommentActivity.this,"has bitmap",Toast.LENGTH_SHORT).show();
} else {
Log.d("Bitmap is null ","after callback");
Toast.makeText(CommentActivity.this,"bitmap is null",Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
Log.d("Bitmap ","after callback failure");
Toast.makeText(CommentActivity.this,"Failure",Toast.LENGTH_SHORT).show();
}
}, CallerThreadExecutor.getInstance());
} catch (Exception e){
e.printStackTrace();
} finally {
if (dataSource != null) {
dataSource.close();
}
}
}
}
}
}
注意:我试图从jpg 图像而不是任何动画 gif图像中获取位图