我想从网络加载 svg 文件并在 ImageView 中显示该文件。对于非矢量图像我使用Picasso http://square.github.io/picasso/图书馆。
是否也可以将此库用于 svg 文件?
有没有办法从网络加载 svg 文件并将其显示在 ImageView 中?
我用svg-android https://code.google.com/p/svg-android/库来显示 svg 文件,但我不知道如何从网络获取 svg 图像,该库的所有示例都使用本地文件。
更新:对于新版本,请查看 Glide 示例
(https://github.com/bumptech/glide/tree/master/samples/svg https://github.com/bumptech/glide/tree/master/samples/svg)
-
您可以使用滑行(https://github.com/bumptech/glide/tree/v3.6.0 https://github.com/bumptech/glide/tree/v3.6.0) 和 AndroidSVG (https://bitbucket.org/paullebeau/androidsvg https://bitbucket.org/paullebeau/androidsvg).
还有一个来自 Glide 的示例:https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app
设置 GenericRequestBuilder
requestBuilder = Glide.with(mActivity)
.using(Glide.buildStreamModelLoader(Uri.class, mActivity), InputStream.class)
.from(Uri.class)
.as(SVG.class)
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
.sourceEncoder(new StreamEncoder())
.cacheDecoder(new FileToStreamDecoder<SVG>(new SvgDecoder()))
.decoder(new SvgDecoder())
.placeholder(R.drawable.ic_facebook)
.error(R.drawable.ic_web)
.animate(android.R.anim.fade_in)
.listener(new SvgSoftwareLayerSetter<Uri>());
将 RequestBuilder 与 uri 一起使用
Uri uri = Uri.parse("https://de.wikipedia.org/wiki/Scalable_Vector_Graphics#/media/File:SVG_logo.svg");
requestBuilder
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
// SVG cannot be serialized so it's not worth to cache it
.load(uri)
.into(mImageView);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)