安卓从网络获取图片

    String path = "www.sjljg.com/image"
        //获取HttpClient 对象  
        HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(path);
    try {  
            //请求httpClient
            HttpResponse response = httpClient.execute(httpPost);  
            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){  
                HttpEntity httpEntity = response.getEntity();  
                InputStream is = httpEntity.getContent();  
                System.out.println(is.available());  
                Bitmap bitmap = BitmapFactory.decodeStream(is);  
                is.close();  
                image.setImageBitmap(bitmap);  
    //或者
    // byte[] result = EntityUtils.toByteArray(response.getEntity());
        }
        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  

你可能感兴趣的:(安卓从网络获取图片)