首页 > 安卓6.0,从系统图库选择照片,裁剪,并显示的问题。

安卓6.0,从系统图库选择照片,裁剪,并显示的问题。

问题是:当我点击选择按钮时,确实跳到图库。但是选择完照片,却没有跳转到裁剪界面?这是为什么?代码逻辑有问题吗?
全局变量: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();
                    }
                }

你这段代码 i.putExtra("crop", true);应该写成 i.putExtra("crop", "true");

Intent设置setType("image/*");时:Extra中可以设置的数据与类型

【热门文章】
【热门文章】