Java 我想裁剪图像以设置配置文件

Java 我想裁剪图像以设置配置文件,java,android,Java,Android,我是新来的,正在学习android开发。我想裁剪图像以设置个人资料图片。当我使用下面的代码时,它没有跳转去捕捉(出了问题)。请帮我解决这个问题。在xml上使用图像视图,并在mainfest上获得读写权限。并使用ArthurHub/Android图像裁剪器进行裁剪功能 enter code here select_image.setOnClickListener(new View.OnClickListener() { @Override public void

我是新来的,正在学习android开发。我想裁剪图像以设置个人资料图片。当我使用下面的代码时,它没有跳转去捕捉(出了问题)。请帮我解决这个问题。在xml上使用图像视图,并在mainfest上获得读写权限。并使用ArthurHub/Android图像裁剪器进行裁剪功能

enter code here  select_image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            premission();

            if (pre == 2) {
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                Log.d("pp", "pp");
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, SELECT_PHOTO);
            }
        }
    });

    protected void onActivityResult(int requestCode, int resultCode, Intent data)
      { super.onActivityResult(requestCode, resultCode, data);

    try
    {
        if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data)
        {

            CropImage.activity()
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .setAspectRatio(1, 1)
                    .start(this);
            Uri selectedImage = data.getData();
        }



        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
        {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);

            if (resultCode == RESULT_OK)
            {
                 Uri selectedImage = result.getUri();


                String[] filePathColumn = {MediaStore.Images.Media.DATA};
                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();


                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                imgDecodableString = cursor.getString(columnIndex);
                cursor.close();

                profileimage.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
                Drawable myDrawable = profileimage.getDrawable();
                profileimage.buildDrawingCache();
                Bitmap bmap = profileimage.getDrawingCache();
                BitmapDrawable bitmapDrawable = ((BitmapDrawable) myDrawable);
                Bitmap bitmap1 = bitmapDrawable.getBitmap();
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap1.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                imageInByte = stream.toByteArray();
                encoded = Base64.encodeToString(imageInByte, Base64.DEFAULT);



            } else
                {

                Toast.makeText(this, "You have not picked Image",
                        Toast.LENGTH_LONG).show();
                }
        }

    }
    catch (Exception e)
    {

        Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();

    }
}

卸下
烤面包片
。使用
Log.e()
将异常记录到Logcat。然后,使用Logcat检查与崩溃关联的堆栈跟踪:。请注意,使用
DATA
列在Android 10及更高版本上不起作用(在旧设备上也不可靠)。嘿,七星,欢迎使用Stack Overflow!正如这个用户共享软件的同事所建议的,请提供堆栈跟踪(错误消息),以便我们能够获得更多关于它的信息!