I post my code here, which, First save the captured image to the local directory and Fetch it from directory and crop. I need to CAPTURE THE IMAGE AND IMMEDIATELY CROP IT THEN SAVE. Is it possible to save the captured image in Bundle/Intent Extra and then Invoke the Crop Function?
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, 1);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1){
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
try {
cropCapturedImage(Uri.fromFile(file));
}
catch(ActivityNotFoundException aNFE){
String errorMessage = "Sorry - your device doesn't support the crop action!";
Toast toast = Toast.makeText(getContext(), errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
if(requestCode==2){
Bundle extras = data.getExtras();
Bitmap thePic = extras.getParcelable("data");
proofImage.setImageBitmap(thePic);
}
}
public void cropCapturedImage(Uri picUri){
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, 2);
}
You can do it either ways :
You can pick images from a URL instead of URI and crop it using glide
Glide.with(this).load(value) .crossFade() .thumbnail(0.5f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(callerimg);
You could use .bitmapTransform(new CircleTransform(this)) to shape in circle. Here CircleTransform is a class which shape picked image in a circle.