Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 尝试使用Fresco从uri获取位图大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用Fresco使用 ImagePipeline获取Bitmap时,不明白行为.当我调试我的代码时,它正在执行onNewResultImpl或onFailureImpl,当我运行应用程序不工作意味着它没有被调用onFailureImpl或onNewResultImpl(我在运行应用程序时使用Toast和Log检查它).我见过这个 SO Question and take ref from it from Fresco's doc.
@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 ","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图

解决方法

我已经删除了try并最终阻止并关闭了onNewResultImpl和onFailureImpl中的Datasource

代码

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());

大佬总结

以上是大佬教程为你收集整理的android – 尝试使用Fresco从uri获取位图全部内容,希望文章能够帮你解决android – 尝试使用Fresco从uri获取位图所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。