BitmapFactory 解析网络请求的inputstream

new Thread(new Runnable() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                
                try {
                    URL url = new URL("http://i4.pdim.gs/dmfd/200_200_100/t01c68b8a60e949ca92.png");
                    
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();
                    con.setRequestMethod("GET");
                    con.setReadTimeout(2000);
                    con.setConnectTimeout(2000);
                    con.connect();
                    InputStream inputStream = con.getInputStream();
                    //转化成图片
                    final Bitmap map = BitmapFactory.decodeStream(inputStream);
                                          inputStream.close();
                    //设置
                    runOnUiThread(new Runnable() {
                        
                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            iv.setImageBitmap(map);
                        }
                    });
                    
                    if (con.getResponseCode() == 200) {
                        
                        Log.e("dd", con.getResponseCode()+"");
                    }else {
                        
                        Log.e("dd","haha");
                    }
                    
                    
                    System.out.println(map.toString());
                    
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Log.e("cc", e.toString());
                    }
                
            }
        }).start();

你可能感兴趣的:(BitmapFactory 解析网络请求的inputstream)