拍照后裁剪
private void doTakePhotoAction() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Wysie_Soh: Create path for temp file mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "tmp_contact_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); try { intent.putExtra("return-data", true); startActivityForResult(intent, PICK_FROM_CAMERA); } catch (ActivityNotFoundException e) { //Do nothing for now }}protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { return; } switch (requestCode) { case CROP_FROM_CAMERA: { //Wysie_Soh: After a picture is taken, it will go to PICK_FROM_CAMERA, which will then come here //after the image is cropped. final Bundle extras = data.getExtras(); if (extras != null) { Bitmap photo = extras.getParcelable("data"); mPhoto = photo; mPhotoChanged = true; mPhotoImageView.setImageBitmap(photo); setPhotoPresent(true); } //Wysie_Soh: Delete the temporary file File f = new File(mImageCaptureUri.getPath()); if (f.exists()) { f.delete(); } InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(mPhotoImageView, InputMethodManager.SHOW_IMPLICIT); break; } case PICK_FROM_CAMERA: { //Wysie_Soh: After an image is taken and saved to the location of mImageCaptureUri, come here //and load the crop editor, with the necessary parameters (96x96, 1:1 ratio) Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.camera", "com.android.camera.CropImage"); intent.setData(mImageCaptureUri); intent.putExtra("outputX", 96); intent.putExtra("outputY", 96); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); startActivityForResult(intent, CROP_FROM_CAMERA); break; } }}?具体可以参考
http://www.androidworks.com/crop_large_photos_with_android
} finally {
Util.closeSilently(outputStream);
}
Bundle extras = new Bundle();
setResult(RESULT_OK, new Intent(mSaveUri.toString())
.putExtras(extras));
}
I have attached some example code that should allow you to test various configurations. ?Let me know if you find it useful (or not).D
Download here ->?MediaStoreTest
From the code (the essential parts)
final Bundle extras = data.getExtras();
if (extras != null) {
File tempFile = getTempFile();
// new logic to get the photo from a URI
if (data.getAction() != null) {
processPhotoUpdate(tempFile);
}
}
}
break;
}
}