¾È±Ô °øºÎ¹æ

Android > ±âº» Gallery¿¡¼­ ¼±ÅÃµÈ Image °¡Á®¿À±â

µî·ÏÀÏ : 2017-07-06 17:50 Á¶È¸¼ö : 145,036

±âº» Gallery¸¦ ¿­¾î Image¸¦ ¼±ÅÃÇØ ¿Ã ¹öÆ° Çϳª¿Í ¼±ÅÃÇÑ Image¸¦ º¸¿©ÁÙ ImageView¸¦ ¹èÄ¡




¹öÆ° Ŭ¸¯ ½Ã ±âº» Gallery·Î À̵¿
 
	public class gallery1 extends Activity {
	
		final int REQ_CODE_SELECT_IMAGE=100;


		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
	

			......
			
			//¹öÆ° Ŭ¸¯½Ã 󸮷ÎÁ÷ 
			Intent intent = new Intent(Intent.ACTION_PICK);                
			intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
			intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
			startActivityForResult(intent, REQ_CODE_SELECT_IMAGE); 

			......

		}

	}



¼±ÅÃÇÑ À̹ÌÁö µ¥ÀÌÅÍ ¹Þ±â
 
		@Override 
		protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
			
			
			Toast.makeText(getBaseContext(), "resultCode : "+resultCode,Toast.LENGTH_SHORT).show();
			
			if(requestCode == REQ_CODE_SELECT_IMAGE) 
			{ 
				if(resultCode==Activity.RESULT_OK) 
				{     
					try { 
						//Uri¿¡¼­ À̹ÌÁö À̸§À» ¾ò¾î¿Â´Ù. 
						//String name_Str = getImageNameToUri(data.getData()); 

						//À̹ÌÁö µ¥ÀÌÅ͸¦ ºñÆ®¸ÊÀ¸·Î ¹Þ¾Æ¿Â´Ù. 
						Bitmap image_bitmap 	= Images.Media.getBitmap(getContentResolver(), data.getData());
						ImageView image = (ImageView)findViewById(R.id.imageView1); 

						//¹èÄ¡ÇسõÀº ImageView¿¡ set 
						image.setImageBitmap(image_bitmap);     
						
						
					//Toast.makeText(getBaseContext(), "name_Str : "+name_Str , Toast.LENGTH_SHORT).show();

					
					} catch (FileNotFoundException e) { 
						// TODO Auto-generated catch block 
						e.printStackTrace(); 
					} catch (IOException e) { 
						// TODO Auto-generated catch block 
						e.printStackTrace(); 
					} catch (Exception e)
					{
	            		e.printStackTrace();
					} 
				}     
			}   
		}
		
	


Uri ¿¡¼­ ÆÄÀϸíÀ» ÃßÃâÇÏ´Â ·ÎÁ÷
		public String getImageNameToUri(Uri data) 
		{ 
			String[] proj = { MediaStore.Images.Media.DATA }; 
			Cursor cursor = managedQuery(data, proj, null, null, null); 
			int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

			cursor.moveToFirst(); 

			String imgPath = cursor.getString(column_index); 
			String imgName = imgPath.substring(imgPath.lastIndexOf("/")+1); 

			return imgName; 
		} 







À̹ÌÁö Crop ±â´É ³Ö±â
 
	// cropµÈ À̹ÌÁö°¡ ÀúÀåµÉ °æ·Î¸¦ ¼³Á¤
        File tempFile = new File(Environment.getExternalStorageDirectory() + "/temp.jpg");
        Uri tempUri = Uri.fromFile(tempFile);
  
	    intent.putExtra("crop", "true");
	    intent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);

	    intent.setType("image/*");




Á¢±Ù ±ÇÇÑÀº ¿ÜÀå¸Þ¸ð¸®¸¦ ¼³Á¤ÇØ Áà¾ß ÇÕ´Ï´Ù.
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
¤¾¤¢¤¾¤¢    2018-01-10 16:55
»èÁ¦
¾Èµå·ÎÀÌµå °øºÎÇÏ´Â ÇлýÀÔ´Ï´Ù~ Á˼ÛÇÏÁö¸¸ Uri ¿¡¼­ ÆÄÀϸíÀ» ÃßÃâÇÏ´Â ·ÎÁ÷ ºÎºÐ ¼³¸í Á» ÇØÁֽðڽÀ´Ï±î ¤Ð¤Ð ÄÚµåµéÀÌ ÀÌÇØ°¡ À߾ȵ˴ϴ٠±¸±Û¸µÇÏ°íÀִµ¥ Äڵ忡 ´ëÇÑ ¼³¸íº¸´Ù´Â È°¿ë ÇÏ´Â°Ô ¸¹ÀÌ ³ª¿À³×¿ä...
 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.