【问题标题】:Loading .svg file from web or local cache in Android在 Android 中从 Web 或本地缓存加载 .svg 文件
【发布时间】:2019-07-31 03:57:55
【问题描述】:

我正在使用Glide 异步加载.png 图像。

File file = Glide.with(context).load(location).downloadOnly(1024, 1024).get();

.svg 的情况下,文件已创建但未加载到ImageView

【问题讨论】:

    标签: android svg android-glide androidsvg


    【解决方案1】:

    ImageView 只接受位图或 VectorDrawables。

    SVG 不是两者之一,即使 VectorDrawable 是它的后代。

    从您的SVG 文件中获取PictureDrawable。然后你需要从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;
    

    【讨论】:

    • 其实我需要加载.svg文件后的文件名
    • 我们不能使用 .svg 文件,我将它们转换为 xml 然后使用它们。
    • 我在 Android 中使用传单并在 webview 上显示图像。我正在使用 glide 从本地缓存加载图像,然后将本地缓存的位置返回给传单。对于.svg,它不起作用
    • 我认为首先您必须将 .svg 转换为位图,然后将本地缓存的位置返回到传单。
    • 那么问题来了,如何远程加载.svg文件。就像滑翔一样
    猜你喜欢
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 2014-01-19
    相关资源
    最近更新 更多