Glide 无法加载某些图像因异常而失败

问题描述 投票:0回答:5

我有图像加载问题。只有一些图像未加载。我试过使用滑行和图像加载器。

滑行代码:

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

滑动依赖:

 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

请检查!

android android-glide android-image
5个回答
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);

3
投票

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

 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) { }
                });

2
投票

谢谢大家的回答和建议。我已经解决了这个问题。我的 URL 参数有问题,它是

?w=430&h=275
而不是
&w=430&h=275
。由于这张图片没有被裁剪,加载大图时出现问题,所以我通过更改参数解决了它


1
投票

glide加载大图有问题

要么使用 Picasso 库

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

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


0
投票

您也可以通过更改上下文来尝试,例如 applicationcontext,或 base context

© www.soinside.com 2019 - 2024. All rights reserved.