关于高德地图,自定义Marker使用自己的XMl,Fresco加载图片流程

因为高德地图的marker在设置自定的view时将view转换成图片,所以不能使用网络图片,这时就要我们自己处理。(ios可以android就要自己处理)大概思路就是,先读取缓存中是否有此图片,有则直接设置到marker的view中的imageview中,如果没有就要监听图片加载流程,图片加载完毕时,在设置一遍view到marker中,Fresco加载图片代码如下。

 vw = LayoutInflater.from(context).inflate(R.layout.view_mark_res, null);
            //判断缓存中是否存在
            boolean isCacheInDisk = Fresco.getImagePipelineFactory().getMainFileCache().hasKey(new SimpleCacheKey(tu));
            if (isCacheInDisk) {//如果存在直接拿出数据
                BinaryResource resource = ImagePipelineFactory.getInstance()
                        .getMainFileCache().getResource(new SimpleCacheKey(tu));
                if (null != resource) {
                    File file = ((FileBinaryResource) resource).getFile();//此处会有FileBinaryResource.getFile()' on a null object  BUG
                    bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
                    ((ImageView) vw.findViewById(R.id.iv_img)).setImageBitmap(bitmap);
                } else {
                    getFrescoCacheBitmap(Uri.parse(tu), context);
                }
            } else
                getFrescoCacheBitmap(Uri.parse(tu), context);

 private void getFrescoCacheBitmap(Uri uri, final Context context) {
        // final Bitmap frescoTepBm;
        ImageRequest imageRequest = ImageRequestBuilder
                .newBuilderWithSource(uri)
                .setProgressiveRenderingEnabled(true)
                .build();
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        DataSource<CloseableReference<CloseableImage>>
                dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
        dataSource.subscribe(new BaseBitmapDataSubscriber() {
            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
            @Override
            public void onNewResultImpl(Bitmap b) {
                bitmap = b;
                View vw = LayoutInflater.from(context).inflate(R.layout.view_mark_res, null);
                if (null != marker) {
                    ((ImageView) vw.findViewById(R.id.iv_img)).setImageBitmap(b);
                    if (rt == 2)
                        vw.findViewById(R.id.iv_play).setVisibility(View.VISIBLE);
                    marker.setIcon(BitmapDescriptorFactory.fromView(vw));
                }
            }

            @Override
            public void onFailureImpl(DataSource dataSource) {
                LogUtils.e(TAG, " onFailureImp");
            }
        }, CallerThreadExecutor.getInstance());
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值