Android 將服務器地址圖片轉成Bitmap

public static void getImage(String path) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(path);
            try {
                HttpResponse httpResponse = httpClient.execute(httpGet);
                if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    byte[] data = EntityUtils.toByteArray(httpResponse
                            .getEntity());
                    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (httpClient != null
                        && httpClient.getConnectionManager() != null) {
                    httpClient.getConnectionManager().shutdown();
                }
            }

        }
    }).start();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章