I need a method to automatically rotate the picture after i have captured it.
It needs to automatically pick up the rotation and correct it.
When i take a photo,It gets rotated 90 degrees anti clockwise.
private void CompressAndSetImage(Uri uri)
{
Bitmap thumbnail = null;
try {
thumbnail = MediaStore.Images.Media.getBitmap(getActivity().getApplicationContext().getContentResolver(), uri);
int nh = (int) ( thumbnail.getHeight() * (1024.0 / thumbnail.getWidth()) );
Bitmap scaled = Bitmap.createScaledBitmap(thumbnail, 1024, nh, true);
Bitmap squareImage = cropToSquare(scaled);
CurrImageURI = getImageUri(getActivity().getApplicationContext(), squareImage);
iv_child.setImageURI(CurrImageURI);
isImageUploaded = true;
} catch (IOException e) {
Toast.makeText(getContext(), "Some error occured", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
private Bitmap cropToSquare(Bitmap bitmap){
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = (height > width) ? width : height;
int newHeight = (height > width)? height - ( height - width) : height;
int cropW = (width - height) / 2;
cropW = (cropW < 0)? 0: cropW;
int cropH = (height - width) / 2;
cropH = (cropH < 0)? 0: cropH;
Bitmap cropImg = Bitmap.createBitmap(bitmap, cropW, cropH, newWidth, newHeight);
return cropImg;
}
private Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
Thanks .