Take Picture, then edit saved picture problem!
I am very new to programming and am attempting to make an app using the onboard cameras hardware, my intent is to take a picture; then when you click save that picture is brought up in a new activity to be edited... I have looked for a couple of days on how to best use the cameras hardware... I was told startActivity(new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE));
followed would 开发者_运维百科initialize the camera the easiest... I have gotten the camera to initiate and even save the picture but my problem lies with; once I press save on the camera, the camera activity reloads instead of kicking the saved picture to a new activity where it can be edited... I know I may sound like a complete noob, and I am but if anyone understands this and can help I would be so appreciative.
Adam,
In my app I use the following code to Launch the camera:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mSelectedImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
This will save the image to the path mSelectedImagePath
which is /sdcard/MyApp/<systemtime>.jpg
.
Then you capture the return of the IMAGE_CAPTURE
intent in onActivityResult
and launch your activity to edit the image from there!
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch(requestCode) {
case TAKE_PICTURE:
//Launch ImageEdit Activity
Intent i = new Intent(this, ImageEdit.class);
i.putString("imgPath", "mSelectedImagePath");
startActivity(i);
break;
}
}
}
Hope this helps!
精彩评论