| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3647 人关注过本帖
标题:BitmapFactory.decodeByteArray返回值为null
只看楼主 加入收藏
xinzhong417
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-6-27
收藏
 问题点数:0 回复次数:0 
BitmapFactory.decodeByteArray返回值为null
从javaweb获取一张图片的数据流,方法如下:
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        PrintWriter writer = response.getWriter();
        InputStream inputStream = this.getServletContext().getResourceAsStream("/WEB-INF/pics/4.jpg");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String str;
        while((str=bufferedReader.readLine())!=null){
            writer.write(str);
            System.out.println("str="+str);
        }
        writer.flush();
        writer.close();
然后android客户端获取此数据流,
public static ByteArrayOutputStream readParse(String urlPath) throws Exception {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[1024];
        int len = 0;
        URL url = new URL(urlPath);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        Log.i("xin", "conn="+conn);
        InputStream inStream = conn.getInputStream();
        
        while ((len = inStream.read(data)) != -1) {
            outStream.write(data, 0, len);

        }
        inStream.close();
        return outStream;

    }
然后调用上面的方法:
            ByteArrayOutputStream readParse = readParse(urlPath);
            byte[] byteArray = readParse.toByteArray();
            Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
却获得bitmap 为null,经验证从服务器端获取到了数据,byteArray 不为空。
求大神指点一下
搜索更多相关主题的帖子: null javaweb 数据流 
2012-08-03 15:30
快速回复:BitmapFactory.decodeByteArray返回值为null
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047298 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved