【问题标题】:java.lang.IllegalStateException:New Glide Version Failed To Load SVG Imagejava.lang.IllegalStateException:新 Glide 版本无法加载 SVG 图像
【发布时间】:2018-07-28 12:16:00
【问题描述】:

我使用 glide 4.6.1 将图像加载到图像视图中,但它失败了。以前我使用 Glide 3.6.0 在 imageview 中加载图像。 glide 3.6.0 版运行良好,可以完美地从 URL 加载图像。为了让它在 Glide 3.6.0 中运行,我关注了这篇文章 android:load svg file from web and show it on image view。但是,glide 4.6.1 不会在图像视图中加载 SVG 图像并给出异常。

我的代码是:

requestBuilder = GlideApp.with(context)
                .as(PictureDrawable.class)
                .listener(new SvgSoftwareLayerSetter());
requestBuilder.load(uri).into(imageview);

官方的 Glide Github 也展示了这个例子,我也在关注那篇文章 https://github.com/bumptech/glide/tree/master/samples/svg/src/main/java/com/bumptech/glide/samples/svg

我得到的例外是:

com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.lang.IllegalStateException(Failed to find any load path from class android.net.Uri$StringUri to class android.graphics.drawable.PictureDrawable)
 call GlideException#logRootCauses(String) for more detail

有什么方法可以让 Glide 4.6.1 以与 Glide 3.6.0 类似的方式工作来加载 SVG?

【问题讨论】:

    标签: android svg imageview android-glide


    【解决方案1】:

    是的,解决方案缺少 SvgModule 类中的 @GlideModule。所以应该是:

    **@GlideModule** //was missing this
    public class SvgModule extends AppGlideModule {
        @Override
        public void registerComponents(@NonNull Context context, @NonNull Glide glide,
                                       @NonNull Registry registry) {
            registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder())
                    .append(InputStream.class, SVG.class, new SvgDecoder());
        }
    
        // Disable manifest parsing to avoid adding similar modules twice.
        @Override
        public boolean isManifestParsingEnabled() {
            return false;
        }
    }
    

    【讨论】:

    • 是的,这是正确的答案,但如果你使用 kotlin - 不要忘记添加这个 - 将插件:'kotlin-kapt' 应用到你的应用程序模块 build.gradle 并检查bumptech.github.io/glide/doc/generatedapi.html#kotlin ,您还需要添加 'com.github.bumptech.glide:compiler:4.11.0'
    猜你喜欢
    • 2019-09-18
    • 1970-01-01
    • 2021-08-17
    • 2021-07-08
    • 2017-10-06
    • 2016-05-02
    • 2021-01-10
    • 2012-09-29
    • 2018-03-22
    相关资源
    最近更新 更多