There are some old posts here concerning this, but things seem to have changed. Yesterday I got an answer for a straightforward way to crop an image using an intent. The second part of the question is to add rotation functionality to the preview. Does anyone know how I might add this functionality? If it's rather complicated, does anyone know of an example out there?
Asked
Active
Viewed 1,836 times
1
-
Crop intent isn't public and may be misssing on some devices. Luckily you can use [the library](https://github.com/lvillani/android-cropimage) that implements it. Its code is essentially copied from AOSP, and has no logic to handle rotation. So, you must roster the image yourself before you crop it, or maybe after. The big difference is that rotation doesn't have to be interactive, while cropping definitely does. – Alex Cohn Jun 29 '14 at 20:33
2 Answers
2
I came across the same problem and used this work-around hack. The Intent called to crop uses a URI, while most solutions for rotations use the Bitmap. So what I did was:
Retrieve the bitmap from the URI
Bitmap bmCameraCapture = BitmapFactory.decodeFile(Uri.fromFile(photo).getPath());
Where photo is the new file you defined when triggering the camera Intent.
Rotate the bitmap
- Get the URI of the rotated bitmap, I used the code from here
public Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title",null); return Uri.parse(path); }
4 . Trigger the crop intent based on this new URI
I'm assuming you are missing steps 1 & 3 and know how to do the other two.

user1555434
- 63
- 6
0
Try this for implementing rotation
Bitmap bMap = BitmapFactory.decodeResource(getResources(),R.drawable.test);
Matrix mat = new Matrix();
mat.postRotate(90);
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(), mat, true);
BitmapDrawable bmd = new BitmapDrawable(bMapRotate);
image.setImageBitmap(bMapRotate);
image.setImageDrawable(bmd);
Hope it helps

Monika
- 135
- 1
- 12
-
Thanks for replying, but the question is not about how to rotate an image. The question is: How do I add rotation functionality to the preview so that **the user** can rotate the image similarly to how **the user** can crop the image. If you look at the link, you will see how the cropping is accomplish: through an intent. – Katedral Pillon Apr 18 '14 at 18:18