【发布时间】:2015-08-17 11:02:00
【问题描述】:
我正在尝试拍摄图像,将文件路径存储在全局变量中,然后显示缩略图。但是图像保存后无法显示图像。
失败于:
startActivityForResult(takePicture, 0);
//
//Camera Application For new Photo
public void btnPhotoClicked(View v) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Create the file path
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String pictureName = getPictureName();
File imageFile = new File(pictureDirectory, pictureName);
Uri pictureUri = Uri.fromFile(imageFile);
//set the filepath to a global variable
imgurl = pictureUri.toString();
//save the picture
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
//start the activity
startActivityForResult(takePicture, 0);//zero can be replaced with any action code
}
这里是显示功能,与拍照和取照片分开
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
//Set the thumbnail
mImageView.setImageURI(selectedImage);
//set a textfield to the filepath
tximgurl.setText(imgurl);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
mImageView.setImageURI(selectedImage);
tximgurl.setText(imgurl);
}
break;
}
}
【问题讨论】:
标签: android android-intent android-camera android-camera-intent