【问题标题】:Glide not able to load some of images failed with exceptionGlide 无法加载某些图像失败并出现异常
【发布时间】:2019-06-20 06:27:18
【问题描述】:

图片加载有问题。只有一些图像没有加载。我尝试过使用 glide 和 image loader。

滑行代码:

Glide.with(context)
                .load(model.getImage4x3().trim()+"?w=430&h=275")
                .into(holder.mBinding.ivPromotion);

Glide 依赖:

 implementation 'com.github.bumptech.glide:glide:4.9.0'

我也试过:3.9.0、4.0.0、3.6.1、3.8.0

错误:

load failed for http://mcms-uat.mercatus.com.sg/en/-/media/E3BE24B58E1144228C62D2364F4FF543.ashx?rev=50ebbcc572e6488c826a23276ab9bf08 with size [320x240]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 4 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{DirectByteBuffer->Object->Drawable}, DATA_DISK_CACHE, http://mcms-uat.mercatus.com.sg/en/-/media/E3BE24B58E1144228C62D2364F4FF543.ashx?rev=50ebbcc572e6488c826a23276ab9bf08
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->BitmapDrawable->Drawable}

图片:

http://mcms-uat.mercatus.com.sg/en/-/media/E3BE24B58E1144228C62D2364F4FF543.ashx?rev=50ebbcc572e6488c826a23276ab9bf08

请检查!

【问题讨论】:

  • 您似乎缺少 Glide 注释处理器。再次阅读他们的实现:Glide Github
  • HI @Annie 我认为 url 生成有一些问题,您能否在发送到 Glide 之前尝试修剪该 url 字符串,我认为您的 URL 中有一些空间。
  • 您是否在清单中添加了 INTERNET 权限?
  • @PratikDasa 我试过 model.getImage4x3()+"?w=430&h=275".trim() 但还是同样的问题
  • 看来您的代码是正确的。问题出在你的形象上。下载该图像表单网址并检查其尺寸。它是 5120x3840,您要设置为 320x240 大小。编辑/裁剪该远程图像并再次检查。

标签: android android-glide android-image


【解决方案1】:

感谢大家的回答和建议。我已经解决了这个问题。我的 URL 参数有问题,它是 ?w=430&h=275 而不是 &w=430&h=275。由于这张图片没有被裁剪并且在加载大图时出现问题,所以我通过更改参数解决了它

【讨论】:

    【解决方案2】:

    只需使用此方法即可完成。如果它不起作用,那就去 Picasso Library,因为这个问题已经被 Glide 本身 STALED。

     Glide.with(context)
                    .asBitmap()
                    .load("Your Network Image Path")
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new CustomTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                            iv.setImageBitmap(resource);
                            iv.buildDrawingCache();
                        }
                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) { }
                    });
    

    【讨论】:

      【解决方案3】:
      1) Add below dependencies into app/build.gradle      
          annotationProcessor 'com.github.bumptech.glide:compiler:your_glide_version'
      

      2) 将 android:largeHeap="true" 放入清单文件的标签中

      3) 并像下面这样使用

          ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
          Glide.with(context)  // this
             .load(imagePath)
             .placeholder(R.drawable.loading_spinner)
             .into(imageView);
      

      【讨论】:

      • 使用android:largeHeap="true"的原因是什么?大堆不是解决这个问题的方法,即使出现 OOM 问题,大堆仍然不是解决方案。如果应用无法在提供的堆大小下运行,则显然需要引起注意。
      • 如果图像大小很大,则使用 android:largeHeap="true" 来增加堆大小
      • 主要是他得到了关于缓存内存的错误。
      • 请调整图片大小而不是使用 largeheap
      【解决方案4】:

      glide 加载大图有问题

      要么使用毕加索库

      实现'com.squareup.picasso:picasso:2.5.2'

      或者您也可以使用他们网站上提供的 facebook 库(这也可以很好地加载 gif 图像)。

      【讨论】:

        猜你喜欢
        • 2020-07-31
        • 2020-11-03
        • 1970-01-01
        • 1970-01-01
        • 2020-08-17
        • 2017-12-30
        • 2020-04-05
        • 2023-03-22
        相关资源
        最近更新 更多