1

I am working on Android application in which I want to pass image from gallery. Previously my code take image from drawable and send it to cropping class. Now I want to use my gallery pic which I have selected instead of R.id.cropImg.

My code for gallery image with URI is also given below:

// for image gallery

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
// OnActivity 
if (requestCode == SELECT_PICTURE) {
   final Uri selectedImageUri = data.getData();
   //showLoadingDialog();
   if (Build.VERSION.SDK_INT < 19) {
       selectedImagePath = getPath(selectedImageUri);
       int   index=1;
       mIntent.putExtra("index", index);
       startActivityForResult(mIntent, requestCode);
   }
}
// now I want to give the location of my image in place
// of R.id.cropImg

setContentView(R.layout.fragment_cropimage);
final CropImageView mCropImage = (CropImageView)findViewById(R.id.cropImg);
mCropImage.setDrawable(getResources().getDrawable(R.drawable.precrop),300,300);

// Before galley it was taking img from drawable for
// cropping, now I want from gallery.
2
  • CropImageView I think extends ImageView, if so, you can just decode the image from the Uri. See this for help
    – Saif Hamed
    Dec 20, 2014 at 21:17
  • Check if 'CropImageView' takes 'Bitmap' as param and crop it. Btw please, take some more time how to properly format your code while posting questions here. Mar 13, 2018 at 17:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.