본문 바로가기

개발도구/aOS - 안드로이드 개발

[안드로이드] URL을 이용 imageview 사용하기 Bitmap

Bitmap imgBitmap = GetImageFromURL("https://t1.daumcdn.net/cfile/tistory/112CA2274C2220D2B4");

if (imgBitmap != null) { ImageView imgView = (ImageView)findViewById(R.id.ImageView); imgView.setImageBitmap(imgBitmap);
 }




private Bitmap GetImageFromURL(String strImageURL) { Bitmap imgBitmap = null; try { URL url = new URL(strImageURL); URLConnection conn = url.openConnection(); conn.connect(); int nSize = conn.getContentLength(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream(), nSize); imgBitmap = BitmapFactory.decodeStream(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } return imgBitmap; }