1

I am using the SurfaceHolder.Callback and Camera.PictureCallback to open Camera in my activity After taking image i want to crop that image and then save it to sd card. I found many solution for cropping via intent camera but didn't find any solution as per my Requirement.
I'll be thankful if someone help me.

Thanks in Advance.

deepak Sharma
  • 1,641
  • 10
  • 23

1 Answers1

1

You should implement Camera.PreviewCallback instead of Camera.PictureCallback,

by using the interface implemented method:

public void onPreviewFrame(byte[] data, Camera camera) {
   if (shutterEnabled){
      shutterEnabled = false;

      // Process data
      // Put it on a Bitmap
      // Send it to cropImage
      // -----
   }
}

Take in account that if you didn't set on your camera parameters, setPreviewFormat, the picture on viewPreviewFrame would arrive as YUV (NV21) format. Actually I'm looking how to make this part, this is why I bumped into your question.

The point here, how are you going to pass the picture to the crop method, you should look into that.

The shutterEnabled flag, it's enabled from your listener that 'watches' for that event.

private void cropImage( picture){
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picture, "image/*");
        cropIntent.putExtra("aspectX",0);
        cropIntent.putExtra("aspectY",0);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, CAMERA_CROP_CODE);
    }


    protected void onActivityResult(int requestCode, int resultCode, Intent data){

     if (resultCode == RESULT_OK && requestCode == CAMERA_CROP_CODE){
                Bitmap bmp = (Bitmap)data.getExtras().get("data");

    }
}
Mario
  • 150
  • 3
  • 11
  • 1
    HI mario Thanks for your precious answer but this is not success on every device of android. for cropping image i got one link.http://stackoverflow.com/questions/16182120/custom-android-image-crop. – deepak Sharma Jul 15 '13 at 12:56