How to load an SVG file from an SD card into ImageView?

I am trying to download an svg file downloaded to an SD card using Picasso, but it does not work.

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+"/secciones.svg");
Picasso.with(context).load(file).into(holder.ivIcon);

I found this question before, but it loads a file from assets. Download the vector transferred to the image from the SD card

Can I upload downloaded to imageView.svg?

+4
source share
2 answers

We cannot use SVG with the android application. (yes ... there are third-party libraries that we can use to work with SVG files)

Source: Android - Working with VectorDrawable

VectorDrawable images - xml , (, , ..) , . vectorDrawable , . apk, .

0

, SVG drawable, ImageView. ( ) , . :

File dir = Environment.getExternalStorageDirectory();
    File yourFile = new File(dir, "your_file_path/filename.svg");
    try {
        FileInputStream fileInputStream = new FileInputStream(yourFile);
        SVG svg = SVGParser.getSVGFromInputStream(fileInputStream);
        Drawable drawable = svg.createPictureDrawable();
        imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        imageView.setImageDrawable(drawable);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
0

Source: https://habr.com/ru/post/1668767/


All Articles