I have a fragment which contains four images each image when clicked it opens a gallery for the user to select image from there in the activity result when retrieving the image name and path I'm passing this result to an activity through intent that handles the cropping of the image in the cropping activity after the cropping is done i don't know how to send back the result of the cropped image to the fragment and place it in the image view same process is done for the 4 images how can i achieve that. Here is my starting code.
enter code here
attach_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickFromGallery();
}
});
private void pickFromGallery()
{
Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == getActivity().RESULT_OK
&& null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getContext().getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
assert cursor != null;
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
startCrop(imgDecodableString);
} else {
Toast.makeText(getActivity(), "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
private void startCrop(String imageUri)
{
Intent intent = new Intent(getActivity(),CropActivity.class);
intent.putExtra("Image",imageUri);
startActivity(intent);
}
} in my cropping activity here is my code
enter code here
Intent i = getIntent();
image = i.getStringExtra("Image");
Log.d("Image",""+image);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int imageWidth = (int) ( (float) metrics.widthPixels / 1.5 );
int imageHeight = (int) ( (float) metrics.heightPixels / 1.5 );
bitmap = BitmapLoadUtils.decode(image, imageWidth, imageHeight);
imageCropView.setImageBitmap(bitmap);
imageCropView.setAspectRatio(3, 2);
findViewById(R.id.crop_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(!imageCropView.isChangingScale())
{
Bitmap b = imageCropView.getCroppedImage();
}
}
});
after cropping here the image i need to set this cropped image in the image view in the fragment same for the rest of the image with the same process how can this be achieved . Any help would be appreciated.