我想拍摄一张照片并将其放入一张imageView中。我设法打开相机,每当我拍摄照片时,都会让我拍摄一张照片。 这是我的onCreate方法:拍摄一张照片,然后将其显示到ImageView
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
File photo = dispatchTakePictureIntent();
ImageView imgView = (ImageView) findViewById(R.id.DisplayImageView);
if(photo.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(photo.getAbsolutePath());
imgView.setImageBitmap(myBitmap);
}
}
这是我的拍照方法:
private File dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Toast.makeText(this, "Failed to create the image file!", Toast.LENGTH_SHORT).show();
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
return photoFile;
}
我需要一个后照片要回从相机的活动,并查看它。我怎样才能做到这一点?
覆盖'用于拍照后得到结果返回onActivityResult'方法 –