问题是:当我点击选择按钮时,确实跳到图库。但是选择完照片,却没有跳转到裁剪界面?这是为什么?代码逻辑有问题吗?
全局变量:private Uri chooseUri;
//对按钮监听,跳转到图库,并选择照片进项裁剪,并将照片保存为choose_image.jpg
choose_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
File chooseImage = new File(Environment.getExternalStorageDirectory(), "choose_image.jpg");
if (chooseImage.exists())
chooseImage.delete();
try {
chooseImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
chooseUri = Uri.fromFile(chooseImage);
Intent i = new Intent("android.intent.action.PICK");
i.setType("image/*");
i.putExtra("crop", true);
i.putExtra("scale", true);
i.putExtra(MediaStore.EXTRA_OUTPUT, chooseUri);
startActivityForResult(i, CROP_PHOTO);
}
});
//回调函数,并将照片显示出来。
case CROP_PHOTO:
if (resultCode == RESULT_OK) {
try {
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().
openInputStream(chooseUri));
photo.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}