尝试使用Fresco

时间:2015-10-05 13:32:09

标签: android bitmap fresco

当我使用Bitmap Fresco使用ImagePipeline提取onNewResultImpl时,请不要理解这种行为。当我调试我的代码时,它正在执行onFailureImplonFailureImpl,当我运行应用程序不工作意味着它没有被调用onNewResultImplToast(我正在检查它在运行应用时使用Log@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(); } } } } } } )。我已经看到了这个SO Question and take ref from it 以及from Fresco's doc.

=DATEVALUE(LEFT(A1,10))

注意:我试图从 jpg图像获取位图而不是来自任何动画gif 图像

1 个答案:

答案 0 :(得分:13)

我已移除tryfinally阻止并关闭DatasourceonNewResultImpl内的onFailureImpl

代码段

ImageRequest imageRequest = ImageRequestBuilder
                            .newBuilderWithSource(mImageCaptureUri)
                            .setAutoRotateEnabled(true)
                            .build();

ImagePipeline imagePipeline = Fresco.getImagePipeline();
final DataSource<CloseableReference<CloseableImage>>
                            dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);

dataSource.subscribe(new BaseBitmapDataSubscriber() {

      @Override
      public void onNewResultImpl(@Nullable Bitmap bitmap) {
         if (dataSource.isFinished() && bitmap != null){
                  Log.d("Bitmap","has come");
                  bmp = Bitmap.createBitmap(bitmap);
                  dataSource.close();
         }
     }

     @Override
     public void onFailureImpl(DataSource dataSource) {
        if (dataSource != null) {
                dataSource.close();
        }
     }
 }, CallerThreadExecutor.getInstance());