这是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
// TODO Auto-generated method stub
if (requestCode == RESULT_LOAD_IMAGE) {
Toast.makeText(this, "In result", Toast.LENGTH_SHORT).show();
selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
cursor.close();
mOriginal = convertBitmap(picturePath);
mSelected.setImageBitmap(mOriginal);
} else if (requestCode == PIC_CROP) {
Bundle extras = data.getExtras();
Uri filePathFromActivity = (Uri) extras.get(Intent.EXTRA_STREAM);
filePathFromActivity = Uri.parse(getRealPathFromUri(filePathFromActivity));
picturePath = filePathFromActivity.getPath();
Bitmap thePic = extras.getParcelable("data");
// picturePath=selectedImage.getPath();
Log.d("Crop Path", picturePath);
//display the returned cropped image
mSelected.setImageBitmap(thePic);
crop_flag = true;
}
}
在此我可以使用cursor.getSring()获取路径,如果请求代码是用于库(RESULT_LOAD_IMAGE),但是如果请求代码用于裁剪(PIC_Crop),如何获取路径。 我无法理解裁剪图像在系统中保存的位置以及如何在字符串中获取完整路径。