티스토리 뷰

dev/android

LoadImageFromUrl

altvirus 2011. 1. 10. 17:05

public static Bitmap LoadImageFromUrl(String strURL) {
  if ( IsEmpty(strURL) ) return null;
  
  Bitmap bitmap = null;
  HttpClient client = getHttpClient();
  
  InputStream in = null;
  try {
   int pos = strURL.lastIndexOf("/");
   String prefix = strURL.substring(0, pos+1);
   String encURL = prefix + URLEncoder.encode(strURL.substring(pos+1),"US-ASCII");
   HttpGet httpRequest = new HttpGet(encURL);
   
   HttpResponse response = client.execute(httpRequest);
   HttpEntity entity = response.getEntity();
   BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
   in = bufHttpEntity.getContent();
   
   bitmap = BitmapFactory.decodeStream(in);
  } catch(Exception e) {
   Trace(e);
  } finally {
   if (in != null) {
    try {
     in.close();
    } catch(Exception e) {}
   }
  }
  return bitmap;
 }

'dev > android' 카테고리의 다른 글

안드로이드 UI들 모음..  (0) 2011.11.02
AsyncTask  (0) 2011.09.30
AsyncTask  (1) 2011.09.30
공지사항