简体   繁体   中英

Loading .svg file from web or local cache in Android

I'm using Glide to load .png image asynchronously.

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 .

ImageView only accepts Bitmaps or VectorDrawables.

SVG is neither of the two, even if VectorDrawable descends from it.

Get a PictureDrawable from your SVG file. Then you need to create a Bitmap from the size of the PictureDrawable and give it to a 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM