我对编程非常陌生,正在尝试使用车载摄像头硬件制作应用程序,我的目的是拍照;然后,当您单击保存时,该图片会出现在要编辑的新活动中...我已经寻找了几天关于如何最好地使用相机硬件...有人告诉我startActivity(new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE));
接下来会最简单地初始化相机。 ..我已经让相机启动甚至保存图片,但我的问题在于;一旦我在相机上按下保存,相机活动就会重新加载,而不是将保存的图片踢到可以编辑的新活动中......我知道我可能听起来像一个完整的菜鸟,但如果有人理解这一点并且可以帮助我会很感激。
问问题
1304 次
1 回答
4
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!
于 2011-03-01T18:38:20.063 回答