0

I am new here and learning about android development. I want to crop image to set profile pic. when i used below codes its not done its jump to catch(something went wrong). kindly please help me solve this problem. used Image view on xml and got permission read and write on mainfest. And used ArthurHub/Android-Image-Cropper for cropping function

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();

    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
seven star
  • 31
  • 1
  • Remove the `Toast`. Log the exception to Logcat using `Log.e()`. Then, use Logcat to examine the stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this. Note that using the `DATA` column will not work on Android 10 and higher (and is not reliable on older devices). – CommonsWare Dec 08 '19 at 18:34
  • hey seven star, welcome to Stack Overflow! as this fellow user CommonsWare has suggested, please provide the stack trace (the error message) so that we can get more info about it! – miquelvir Dec 08 '19 at 21:03

0 Answers0