[英]Glide not loading SVG
我想显示通过 API 接收到的图像(类型 = SVG)。 出于安全原因,加载时需要验证标头才能获取图像。
这是我的 GlideModule:
@GlideModule
@Excludes(OkHttpLibraryGlideModule.class)
public class GlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
Lazy<UserRepository> repository = inject(UserRepository.class);
registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder()).append(InputStream.class, SVG.class, new SvgDecoder());
OkHttpClient client = new OkHttpClient.Builder()
.readTimeout(15L, TimeUnit.SECONDS)
.connectTimeout(15L, TimeUnit.SECONDS)
.addInterceptor(new AuthInterceptor(repository.getValue()))
.build();
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
我正在使用数据绑定将接收到的图像直接加载到图像视图中:
@JvmStatic
@BindingAdapter("loadSvg")
fun loadSvgImage(view: ImageView, url: String?) {
if (!url.isNullOrEmpty()) {
val uri = Uri.parse(url)
val requestBuilder = GlideApp.with(view)
.`as`(PictureDrawable::class.java)
.listener(SvgSoftwareLayerSetter())
requestBuilder.load(uri).into(view)
}
}
不显示图像,但也没有警告/错误消息。
我的 GlideModule/Binding Function 有问题吗?
我认为它不受支持,如 Glide 代码所示:
enum ImageType {
GIF(true),
JPEG(false),
RAW(false),
/** PNG type with alpha. */
PNG_A(true),
/** PNG type without alpha. */
PNG(false),
/** WebP type with alpha. */
WEBP_A(true),
/** WebP type without alpha. */
WEBP(false),
/** Unrecognized type. */
UNKNOWN(false);
列表中没有 SVG。
然而,有一个名为 PainterSVG 的应用程序似乎也在使用 Glide,我看到了大多数 Glide 功能,如占位符、居中、缩略图。 我不确定他们如何使它与 SVG 一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.