标题: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-374656-1-1.html




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

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