๊ฐ๋ฐ์ ํ๋ค๋ณด๋ฉด ์ฌ์ง์ ๊ฐ์ ธ์ค๊ฑฐ๋ ์ฌ์ง ์ฐ๊ธฐ, ์ด๋ฏธ์ง ํฌ๋กญ ๊ธฐ๋ฅ์ด ํ์ํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ํ์ง๋ง ์ด๋ฐ ๊ธฐ๋ฅ๋ค์ ํ์ํ ๋๋ง๋ค ๊ฐ๋ฐ์ ํ๋ค๋ ๊ฑด ๋นํจ์จ ์ ์ด์ฃ . ๊ทธ๋์ ์๋๋ก์ด๋๋ Intent๋ฅผ ํตํ์ฌ ์ธ๋ถ ์ฑ์ ์ ์ ํ ํ์ฉ ํ ์ ์๋๋ก ๋์ ์ค๋๋ค. ์ฌ์ง ๊ฐ์ ธ์ค๊ธฐ
| private void dispatchPickPictureIntent() { Intent pickPictureIntent = new Intent(Intent.ACTION_GET_CONTENT); pickPictureIntent.setType("image/*"); if (pickPictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(pickPictureIntent, REQUEST_IMAGE_PICK); } } |
์ฌ์ง ์ฐ๊ธฐ
| private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "edp_image.jpg")); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } |
์ฌ์ง ย ํฌ๋กญ
| private void dispatchCropPictureIntent(Uri uri) { Intent cropPictureIntent = new Intent("com.android.camera.action.CROP"); cropPictureIntent.setDataAndType(uri, "image/*"); cropPictureIntent.putExtra("outputX", 640); // cropํ ์ด๋ฏธ์ง์ x์ถ ํฌ๊ธฐ (integer) cropPictureIntent.putExtra("outputY", 480); // cropํ ์ด๋ฏธ์ง์ y์ถ ํฌ๊ธฐ (integer) cropPictureIntent.putExtra("aspectX", 4); // crop ๋ฐ์ค์ x์ถ ๋น์จ (integer) cropPictureIntent.putExtra("aspectY", 3); // crop ๋ฐ์ค์ y์ถ ๋น์จ (integer) cropPictureIntent.putExtra("scale", true); cropPictureIntent.putExtra("return-data", true); if (cropPictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(cropPictureIntent, REQUEST_IMAGE_CROP); } } |
๊ฒฐ๊ณผ ์ฒ๋ฆฌ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case REQUEST_IMAGE_PICK: // dispatchPickPictureIntent() ๊ฒฐ๊ณผ dispatchCropPictureIntent(data.getData()); break; case REQUEST_IMAGE_CAPTURE: // dispatchTakePictureIntent() ๊ฒฐ๊ณผ dispatchCropPictureIntent(mUri); break; case REQUEST_IMAGE_CROP: // dispatchCropPictureIntent() ๊ฒฐ๊ณผ Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); mThumbnail.setImageBitmap(ditherBitmap); break; } } } |
Read More