¾È±Ô °øºÎ¹æ

Android > HttpURLConnection - ¼­¹öÀ̹ÌÁö ºÒ·¯¿À±â ¿¹Á¦

µî·ÏÀÏ : 2017-07-06 17:35 Á¶È¸¼ö : 52,990

¼­¹ö¿¡ ÀÖ´Â À̹ÌÁö¸¦ ImageView ¿¡ »Ñ¸®´Â ¿¹Á¦ ÀÔ´Ï´Ù.
 
	public class LoadImageServer extends Activity {   
		@Override   
		public void onCreate(Bundle savedInstanceState) {   
			super.onCreate(savedInstanceState);   
			setContentView(R.layout.main);   

			String imagePath	= "http://entersoft.kr/images/1.png" ;   
			ImageView imgView	= (ImageView) findViewById(R.id.imgView) ;   
			Bitmap bm = LoadImage( imagePath ) ; // ÀÌ·¸°Ô imagePath¸¸ ³Ö¾îÁÖ¸é, BitmapÀ¸·Î ¹ÝȯÀÌ µÈ´Ù.  
			imgView.setImageBitmap( bm ) ;  // ±× BitmapÀ» Âï±â¸¸ ÇÏ¸é µÈ´Ù. 
		}   

		private Bitmap LoadImage( String imagePath ) { 
			InputStream inputStream = OpenHttpConnection( imagePath ) ;   
			Bitmap bm = BitmapFactory.decodeStream( inputStream ) ;   
			return bm;   
		}   

		private InputStream OpenHttpConnection(String imagePath) {   
			InputStream stream = null ;   
			try {   
				URL url = new URL( imagePath ) ;   
				HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection() ;   
				urlConnection.setRequestMethod("GET");   
				urlConnection.connect() ;   
				if( urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK ) {   
					stream = urlConnection.getInputStream() ;   
				}   
			} catch (MalformedURLException e) {   
				e.printStackTrace();   
			} catch (IOException e) {   
				e.printStackTrace();   
			}   
			
			return stream ;   
		}   
	}  
	



 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.