android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

In fragment return same image while crop different image.

Open amitkumarverma-android opened this issue 9 years ago • 10 comments

private void cropCapturedImage(Uri picUri) { Uri destination = Uri.fromFile(new File(getActivity().getCacheDir(), "cropped")); Crop.of(picUri, destination).asSquare().start(getContext(), EditPersonalInfoFragment.this, Crop.REQUEST_CROP); }

private void handleCrop(int resultCode, Intent result) { if (resultCode == Activity.RESULT_OK) { Uri uri = Crop.getOutput(result); mUserImageView.setImageBitmap(null); Glide .with(mContext) .load(new File(uri.getPath())) .centerCrop() .placeholder(R.drawable.user_placeholder) .dontAnimate() .into(mUserImageView); new SelectedImage().execute(uri.getPath(), LoginManager.getInstance().getUserData().getAuthorID()); ((EditInformationActivity) getActivity()).isProfilePicEdit = true;

    }

}

amitkumarverma-android avatar Oct 13 '16 13:10 amitkumarverma-android

Me too having the same exact issue.

omujeebr avatar Oct 31 '16 09:10 omujeebr

You could solve the problem in fragment ?

amineghabi avatar Nov 01 '16 12:11 amineghabi

Yes i solved it yesterday. Actually it had nothing to do with the crop library. It was because the Picasso caching the old image. In your case the Glide.

I solved this by disabling the cache of Picasso. Hope this will help.

omujeebr avatar Nov 01 '16 12:11 omujeebr

Thanks my friend, just to be sure , when i want the result of the pick from gallery to be delivered to the calling fragment not the activity should i use Crop.pickImage(getActivity()) ; or Crop.pickImage(getContext(), MyFragment) ; ???

amineghabi avatar Nov 01 '16 14:11 amineghabi

You should use Crop.pickImage(getContext(), fragment) ; to receive the result in fragment itself.

omujeebr avatar Nov 01 '16 16:11 omujeebr

It's not the issue of Picasso/Glide cache, you have to do one thing inside beginCrop(Uri source) function you have to replace Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped")); To Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"+ String.valueOf(System.currentTimeMillis()))); Happy coding!

neerajemorphis avatar Apr 18 '17 13:04 neerajemorphis

Thank you! I was going through the same problem.

mtheusbrito avatar Jun 17 '17 23:06 mtheusbrito

While setting Bitmap i'm getting error can u help me out

MustafaAndroid avatar Aug 23 '19 09:08 MustafaAndroid

How can i convert into base64 and send image to server any guide please

MustafaAndroid avatar Aug 23 '19 09:08 MustafaAndroid

Try this one ;) run setDp();

private void setDp() {
        dpic.setImageDrawable(null);
        Crop.pickImage(getContext(), InviteFragment.this);
    }

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent result) {
        if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
            beginCrop(result.getData());
        } else if (requestCode == Crop.REQUEST_CROP) {
            handleCrop(resultCode, result);
        }
    }

    private void beginCrop(Uri source) {
        Uri destination = Uri.fromFile(new File(getContext().getCacheDir(), "cropped"));
        Crop.of(source, destination).asSquare().withMaxSize(300,300).start(getContext(), InviteFragment.this, Crop.REQUEST_CROP);
    }

    private void handleCrop(int resultCode, Intent result) {
        if (resultCode == RESULT_OK) {
            dpUri = Crop.getOutput(result);
            uploadImage();
        } else if (resultCode == Crop.RESULT_ERROR) {
            Toast.makeText(getActivity(), Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
        }
  }

lakpriya1s avatar Nov 02 '19 23:11 lakpriya1s