[英]Loading .svg file from web or local cache in Android
I'm using Glide
to load .png
image asynchronously.我正在使用Glide
异步加载.png
图像。
File file = Glide.with(context).load(location).downloadOnly(1024, 1024).get();
In case of .svg
, the file is created but it is not loading into ImageView
.在.svg
情况下,该文件已创建但未加载到ImageView
。
ImageView only accepts Bitmaps or VectorDrawables. ImageView 只接受位图或 VectorDrawables。
SVG is neither of the two, even if VectorDrawable descends from it. SVG 不是两者中的任何一个,即使 VectorDrawable 是从它派生出来的。
Get a PictureDrawable
from your SVG
file.从您的SVG
文件中获取一个PictureDrawable
。 Then you need to create a Bitmap
from the size of the PictureDrawable
and give it to a Canvas
.然后您需要根据PictureDrawable
的大小创建一个Bitmap
并将其提供给Canvas
。
PictureDrawable pictureDrawable = svg.createPictureDrawable();
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
currentBitmap = bitmap;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.