如何在谷歌图表图形转换为图像中的android? [英] How to convert a google charts graph to image in android?

查看:108
本文介绍了如何在谷歌图表图形转换为图像中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个线图我与谷歌图表API来image.How转换,应该怎么办?我没有在网络上任何可以帮助找到。

I want to convert a line graph I made with google charts api to image.How should I do?I didn't found on the net anything that can help.

推荐答案

试图将谷歌图表转换为位图,并设置为你的形象到您的ImageView。

try to convert your google chart as bitmap and set as your image to your imageview.

为前:

Bitmap bitmap = loadChart("your google image url");

和loadChart方法

and loadChart method is

private Bitmap loadChart(String urlRqs) {
        Bitmap bm = null;
        InputStream inputStream = null;

        try {
            inputStream = OpenHttpConnection(urlRqs);
            bm = BitmapFactory.decodeStream(inputStream);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return bm;
    }

OpenHttpConnection

private InputStream OpenHttpConnection(String strURL) throws IOException {

        InputStream is = null;
          URL url = new URL(strURL);
          URLConnection urlConnection = url.openConnection();

          try{
           HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
           httpConn.setRequestMethod("GET");
           httpConn.connect();

           if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
            is = httpConn.getInputStream(); 
           }
          }catch (Exception ex){
              Log.e("###","",ex);
          }

        return is;
    } 

最后,你可以通过以下code将位图图像视图的背景。

And finally you can set your bitmap as your image view background by using following code.

image.setImageBitmap(bitmap);

试试看。 我希望这会帮助你。

Try it. I hope this will help you.

这篇关于如何在谷歌图表图形转换为图像中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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