ãããã£ã¼ã«åçãã¢ã¤ã³ã³ç»åã®è¨å®ç»é¢ãªããã§ãããããåçãé¸ãã§âããªãã³ã°ãã¦ãã£ã¦ãã¤ã§ãã
ããã¾ãæ¥æ¬èªã®æ
å ±ããªãã£ãã®ã§æ¸ãã¾ãã
ã®ã£ã©ãªã¼ãå¼ã³åºãã¦åçãé¸ã¶
public void onChangePhotoClick(View view) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, REQUEST_GET_CONTENT); }
ããªãã³ã°æ©è½ï¼ã¢ããªï¼ãå¼ã³åºã
åçãé¸ã°ãããonActivityResult()ãå¼ã³åºãããã®ã§ãé¸ã°ããåçã®Uriã使ã£ã¦ããªãã³ã°æ©è½ï¼ã¢ããªï¼ãå¼ã³åºãã¾ãã
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_GET_CONTENT: if (resultCode != RESULT_OK) return; Uri uri = data.getData(); // é¸ã°ããåçã®Uri Intent intent = new Intent("com.android.camera.action.CROP"); intent.setData(uri); intent.putExtra("outputX", 200); intent.putExtra("outputY", 200); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); startActivityForResult(intent, REQUEST_CROP_PICK); break; } }
æã®è¯ã人ã¯Extraã®ãã¼åã§ã ãããæå³ããããã¨æãã¾ãããåãã¼ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
- outputX
- ããªãã³ã°å¾ã®ç»åã®å¹ (px)
- outputY
- ããªãã³ã°å¾ã®ç»åã®é«ã(px)
- aspectX
- ããªãã³ã°å¾ã®ç»åã®ã¢ã¹ãã¯ãæ¯(X)
- aspectY
- ããªãã³ã°å¾ã®ç»åã®ã¢ã¹ãã¯ãæ¯(Y)
- scale
- ããªãã³ã°ä¸ã®æ ãæ¡å¤§ç¸®å°ã§ãããã©ãã
- return-data
- åºæ¬çã«true
ããªãã³ã°ãããç»åãåå¾ãã
ããªãã³ã°ãããç»åãonActivityResult()ã§åãåãã¾ãã
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_GET_CONTENT: // çç¥ case REQUEST_CROP_PICK: if (resultCode != RESULT_OK) return; Bitmap bitmap = data.getExtras().getParcelable("data"); // åå¾ããBitmapã§ãã«ããã«ããã } }
以ä¸ã§ãï¼
ã¬ã·ã105ã«å
¥ãããããã