0

我们正在尝试使用谷歌图表 api 的原型。

http://chart.apis.google.com/chart?chf=bg,s,000000&chxs=0,FFFFFF00,9.5&chxt=x&chs=500x300&cht=p3&chco=3072F3|FF9900|80C65A|990066&chd=t:50,5,5,40&chdl=50%C2%B0%20Apples|5%C2%B0%20Oranges|5%C2%B0%20Dates|40%C2%B0%20Strawberries&chdlp=b&chp=0.1

在此处输入图像描述

问题是当我们在浏览器中看到图表时,它会显示图例。但是当我们使用 BitmapFactory 将图像下载到 ImageView 甚至 SD 卡时,图例会丢失(无论图例放置在顶部、底部、左侧还是右侧,都会发生这种情况)。

这是代码

private Bitmap loadChart(URL url){
    Bitmap chart = null;   

    try{            
        HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
        httpConnection.setDoInput(true);
        httpConnection.connect();

        InputStream is = httpConnection.getInputStream();           
        chart = BitmapFactory.decodeStream(is);


    } catch (IOException e) {       
        e.printStackTrace();
    }

    //MediaStore.Images.Media.insertImage(getContentResolver(), chart, "chart.png", "chart.png");

    return chart;
}

这是注释行下载的图像。

我们还注意到,在 URL (chs=500x300) 中指定的图表尺寸也与图像尺寸匹配。

在此处输入图像描述

4

1 回答 1

0

最终使用 webview 处理 url 编码,无需任何额外的努力。

于 2011-04-13T04:54:51.143 回答