下面的代码将帮助您从相机拍照并将图像设置到下一个活动
private void takePicture() {
cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, IMAGE_CAPTURE);
}
// Receive the result from the start Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("onActivityResult", "we r in onActivityResult");
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case IMAGE_CAPTURE:
File dir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir, "camerascript.png");
cPath = output.getAbsolutePath();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(output));
Intent capIntent = new Intent(yourcurrentActivity.this,
yournextActivity.class);
capIntent.putExtra("gallery", cPath);
startActivity(capIntent);
break;
default:
break;
}
}
}
之后,将 intnet 额外数据放入yournextAactivity
您想要设置捕获图像的位置。
ImageView imageView = (ImageView)findViewById(R.id.imgView);
String fileString = getIntent().getStringExtra("gallery");
imageView.setImageBitmap(BitmapFactory.decodeFile(fileString));