【问题标题】:how to get loaded url from picasso library如何从毕加索库中获取加载的网址
【发布时间】:2016-06-11 03:37:47
【问题描述】:

我正在使用毕加索库在谷歌地图 api 上设置带有图像的标记。但我需要加载从毕加索加载的drawable。

我试过了,但它没有返回从毕加索加载的网址

Target target = new Target() {
          @Override
          public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

          }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {}

        @Override


     public void onPrepareLoad(Drawable placeHolderDrawable) {}
    };

【问题讨论】:

    标签: android picasso


    【解决方案1】:

    在drawable加载之后你不能从Picasso获取URL(Picasso.LoadedFrom只会告诉你图片是否是从DISK加载的,MEMORY 或 网络)。

    但由于您在告诉 Picasso .load() 图像时需要指定 URL,因此您可以简单地将 URL 存储在某个地方并稍后使用它。

    如果您的实际目标是将自定义标记图标从远程 URL 加载到 Google 地图标记中,请使用 ad-hoc ImageView 执行此操作:

    private void loadImageFromUrlIntoMarker(final String url, final Marker marker) {
        final ImageView iv = new ImageView(context);
        Picasso.with(context).load(url).into(iv, new Callback() {
            @Override
            public void onSuccess() {
                Bitmap bm = ((BitmapDrawable) iv.getDrawable()).getBitmap();
                try {
                    marker.setIcon(BitmapDescriptorFactory.fromBitmap(bm));
                } catch (Exception e) {
                    Log.e(getClass().getSimpleName(), "Could not load image into marker.");
                }
            }
    
            @Override
            public void onError() {
                Log.e(getClass().getSimpleName(), "Could not load image from " + url);
            }
        });
    }
    

    try { ... } catch { ... } 很重要,因为当可绘制对象可用时,标记可能无效。

    【讨论】:

      【解决方案2】:

      毕加索的基本用法

          Picasso.with(context).load(my_url).into(my_view);
      

      并使用 gradle 导入库

       compile 'com.squareup.picasso:picasso:2.5.2'
      

      【讨论】:

      • 我不是在寻找那个 :) 我需要在加载图像后获取“my_url”。
      • 网址来自哪里
      【解决方案3】:

      我不知道你为什么问这个问题,因为你需要一个 url 来加载带有 Picasso 的图像。你可以创建一个基本上像这样的函数:

      public void loadimage(final String loadingUrl){
          Picasso.with(getApplicationContext()).load(loadingUrl).into(yourimageview, new Callback() {
              @Override
              public void onSuccess() {
                  Log.v("picasso","i successfully created image, here is url : "+loadingUrl);
              }
      
              @Override
              public void onError() {
      
              }
          });
      }
      

      【讨论】:

      • 我会在google map上显示用户的图片。所以我将加载的url和用户的坐标保存在hashmap中。(HashMap) 所以我需要从picasso为每个用户加载的url。然后我将通过使用坐标键从哈希图中获取图片来将图片设置为标记。我使用universalimageloader来实现它。因为这个库在加载过程后返回图像。但我仍然想知道如何使用毕加索来实现它。
      • 您能否发布您的完整方法以确定您如何使用毕加索。如果您在加载图像时没有任何 url,则必须使用位图或可绘制的东西。然后您可以将它们转换为 base64 并保存字符串键值。请更新您的完整代码,我会帮助您
      • 我现在看到这条评论很抱歉。我认为这是可以接受的。我会尽力通知你。谢谢。
      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      相关资源
      最近更新 更多