android-crop
android-crop copied to clipboard
In fragment return same image while crop different image.
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;
}
}
Me too having the same exact issue.
You could solve the problem in fragment ?
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.
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) ; ???
You should use Crop.pickImage(getContext(), fragment) ; to receive the result in fragment itself.
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!
Thank you! I was going through the same problem.
While setting Bitmap i'm getting error can u help me out
How can i convert into base64 and send image to server any guide please
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();
}
}