0

I have to rotate an image in an angle and crop through android crop intent.When i click a rotate button the image should rotate in an angle and display in Image View and when i click crop button the rotated image should be send to android crop intent.

In this way the angles may be changing whenever i click rotate button and corresponding rotated image displaying in Image View should be cropped through android crop action.

I tried with rotating image in all angles and it is working fine. But whenever i click crop button the rotated image is not passing to crop instead original image is passing.

this is my code

image.setImageURI(imageURI);

    if (savedInstanceState != null) {
        rotation = savedInstanceState.getInt("ANGLE");
    }

    mTempUri = HomeActivity.getOutputMediaFileUri("XXX",
            "test1", MEDIA_TYPE_IMAGE, true);

{

crop.setOnClickListener (new OnClickListener() {

        @Override
        public void onClick(View v) {
            doCrop();
        }
    });

    rotate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(),
                    "Rotating.. Please wait", Toast.LENGTH_SHORT).show();
            rotate_Image();

        }
    });
}

public void doCrop() {

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
            intent, 0);

    int size = list.size();

    if (size == 0) {
        Toast.makeText(this, "Can not find image crop app",
                Toast.LENGTH_SHORT).show();

        return;
    } else {
        intent.setData(imageURI);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mTempUri);

        if (size == 1) {
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent(new ComponentName(res.activityInfo.packageName,
                    res.activityInfo.name));
            startActivityForResult(i, CROP_FROM_CAMERA);
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;

    switch (requestCode) {
    case CROP_FROM_CAMERA:
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://"
                        + Environment.getExternalStorageDirectory())));
        this.finish();
        break;

    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putInt("ANGLE", rotation);
    super.onSaveInstanceState(outState);
}

public void rotate_Image() {
    rotation += 90;
    rotation %= 360;
    bitmap = null;
    try {
        bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),
                imageURI);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    bitmap1 = getRotatedBitmap(bitmap);
    image.setImageBitmap(bitmap1);
}

private Bitmap getRotatedBitmap(Bitmap bitmap) {
    if (rotation % 360 == 0) {
        return bitmap;
    }
    Matrix matrix = new Matrix();
    matrix.postRotate(rotation, bitmap.getWidth() / 2,
            bitmap.getHeight() / 2);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
            bitmap.getHeight(), matrix, true);
}       

}

user3121545
  • 9
  • 1
  • 3
  • follw this link for croping an image http://mobile.tutsplus.com/tutorials/android/capture-and-crop-an-image-with-the-device-camera/ – Shailendra Madda Dec 20 '13 at 05:19
  • possible duplicate of [code to rotate image captured by camera intent not working in Android](http://stackoverflow.com/questions/14123809/code-to-rotate-image-captured-by-camera-intent-not-working-in-android) – Infinite Recursion Dec 20 '13 at 05:34
  • @shylendra i posted my code. In tat after rotation i am setting bitmap image to imageView.But i don't know how to get rotated image displaying in imageview and send that to crop intent. – user3121545 Dec 20 '13 at 05:35

2 Answers2

1

https://github.com/KyoSherlock/CropView

Here is a custom view for cropping image with translation, scale and rotation.(but not an intent) Crop rect is fixed, and image can be translated by gesture.

0

I have used https://github.com/edmodo/cropper,

I found it handy because all the action happens in one ImageView and you can even move/put or remove grids in the cropping rectangle.

Darpan
  • 5,623
  • 3
  • 48
  • 80