I have tried to take a picture and then crop it then stored it on SDCard.
Here are codes, maybe you will be inspired:
Take a photo:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(AVATAR_FILE_TMP));
intent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
startActivityForResult(intent, CODE_TAKE_PHOTO);
Then crop the photo
:
if (requestCode == CODE_TAKE_PHOTO) {
cropImage(Uri.fromFile(AVATAR_FILE_TMP));
}
public void cropImage(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 400);
intent.putExtra("return-data", true);
startActivityForResult(intent, CODE_CROP_IMAGE);
}
And at last, store the picture:
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
// civAvatar.setImageBitmap(photo); // 把图片显示在ImageView控件上
FileOutputStream fos = null;
try {
// store the picture
fos = new FileOutputStream(AVATAR_FILE);
photo.compress(Bitmap.CompressFormat.PNG, 100, fos);// (0-100)compress file.
AVATAR_FILE_TMP.deleteOnExit();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
IoUtils.closeSilently(fos);
finish();
}
}
And if you just store the picture, intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(AVATAR_FILE_TMP));
is OK.