I\'m trying to crop an image after taking it, and my code is as follows:
private void doTakePhotoAction() {
Intent intent = new Intent(MediaStore
Though this might be a very old thread, I was able to crop a picture programmatically with the following code :
btnTakePicture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
then I cropped it with :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
photo = (Bitmap) data.getExtras().get("data");
performcrop();
}
}
private void performcrop() {
DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
Bitmap croppedBmp = Bitmap.createBitmap(photo, 0, 0, width / 2,
photo.getHeight());
imageTaken.setImageBitmap(croppedBmp);
}
imageTaken is an ImageView Component in my view. You can see my source Here