机器人:从网页加载SVG文件,并显示在图像视图 [英] android:load svg file from web and show it on image view

查看:1039
本文介绍了机器人:从网页加载SVG文件,并显示在图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网络加载SVG文件,并显示在一个ImageView的这个文件,对于正常PNG或其他图像文件我用的毕加索
是否有可能使用这个库的SVG文件?是疗法任何方式从网络加载SVG文件,并显示在图像视图?我使用 SVG-的Andr​​oid 库,用于显示SVG文件,但我不知道如何以从网络的所有例子都使用本地文件SVG图像。

i want to load svg file from web and show this file on a imageView , for normal png or other image files i use Picasso library is it possible to use this library for svg files ? is ther any way to load svg file from web and show it on image view ? i use svg-android library for show svg files but i dont know how to get svg image from web all examples use local files.

推荐答案

请参阅<一个href=\"http://stackoverflow.com/questions/18356098/having-issue-on-real-device-using-vector-image-in-android-svg-android\">Having问题在Android的使用矢量图像真实的设备。 SVG-的Andr​​oid

在网友的帖子他问过类似的问题,并建议他使用:

In the users post he asks a similar question and suggest he uses:

在布局文件中创建的ImageView的一个成员变量;

Create a member variable for the ImageView in your layout file;

private ImageView mImageView;

// intialize in onCreate(Bundle savedInstanceState)
mImageView = (ImageView) findViewById(R.id.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);
    }
}

然后绘制适用于ImageView的

Then Apply the drawable to the Imageview

@SuppressLint("NewApi")
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);
        mImageView.setImageDrawable(drawable);
    }
}

SVGParser可在 https://github.com/pents90/svg-android

这篇关于机器人:从网页加载SVG文件,并显示在图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆