1

我想将我用谷歌图表 api 制作的折线图转换为图像。我该怎么办?我在网上没有找到任何可以帮助的东西。

4

1 回答 1

2

尝试将您的谷歌图表转换为位图并将您的图像设置为您的图像视图。

例如:

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

和 loadChart 方法是

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;
    } 

最后,您可以使用以下代码将位图设置为图像视图背景。

image.setImageBitmap(bitmap);

尝试一下。我希望这能帮到您。

于 2013-04-06T12:24:25.377 回答