Android :: BitmapFactrory Cuts off image

淺唱寂寞╮ 提交于 2019-12-25 03:55:25

问题


We are trying a prototype using Google chart 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

the problem is when we see the chart in the browser it displays the legend. but when we use the BitmapFactory to download the image to an ImageView or even SD card the Legend goes missing (this happens irrespective of where the legend is placed top, bottom, left or right).

here is the code

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

here is the image which was downloaded by the commented line.

we also noticed that, the dimension of the chart specified in URL (chs=500x300) matches with the image dimension as well.


回答1:


Ended up using webview which handles url encoding without any additional effort.



来源:https://stackoverflow.com/questions/5454242/android-bitmapfactrory-cuts-off-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!