1

I am trying to download and display an svg image in my ImageView. I am using Picasso to display my other images from the web. However, now I have to show the svg images and I cannot get to decode the image.

This is how I do he rest of the images :-

Picasso.with(context)
                .load(mProject.getAvatar())
                .placeholder(R.drawable.ic_description_blue_grey_600_36dp)
                .error(R.drawable.ic_description_blue_grey_600_36dp)
                .centerCrop()
                .into(holder.thumbnail);

How can I display SVG images from the web? Any help is appreciated.

user3034944
  • 1,321
  • 2
  • 16
  • 33
  • Possible duplicate of [How to show the SVG image in the android imageview](https://stackoverflow.com/questions/25055896/how-to-show-the-svg-image-in-the-android-imageview) – Vikash Parajuli Mar 12 '18 at 09:03
  • Possible duplicate, please check this [link](https://stackoverflow.com/questions/33696488/getting-bitmap-from-vector-drawable) – kishna.147 Mar 12 '18 at 09:06
  • @VikashParajuli I need to download the image from web and then display it to the imageview. The question shows how to display the image which I stored in resources – user3034944 Mar 12 '18 at 09:06

2 Answers2

0

use this library AndroidSvgLoader

-1

used below code for svg file show in as image view..

private class HttpImageRequestTask extends AsyncTask<Void, Void, Drawable> {
    @Override
    protected Drawable doInBackground(Void... params) {
        try {


            final URL url = new URL("http://upload.wikimedia.org/wikipedia/commons/e/e8/Svg_example3.svg");
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            SVG svg = SVGParser. getSVGFromInputStream(inputStream);
            Drawable drawable = svg.createPictureDrawable();
            return drawable;
        } catch (Exception e) {
            Log.e("MainActivity", e.getMessage(), e);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Drawable drawable) {
        // Update the view
        updateImageView(drawable);
    }
}
private void updateImageView(Drawable drawable){
    if(drawable != null){

        // Try using your library and adding this layer type before switching your SVG parsing
        mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        Picasso.with(this)
                .placeholder(drawable) //this is optional the image to display while the url image is downloading
                .error(Your Drawable Resource)         //this is also optional if some error has occurred in downloading the image this image would be displayed
                .into(imageView);

    }
}
Mobile Team ADR-Flutter
  • 12,062
  • 2
  • 29
  • 49