Xamarin - How to correct the orientation of a picture captured from Android device
Start
How to correct the orientation of a picture captured from Android device
This example shows how to take image and display it correctly on the Android device.
Firstly we have to create sample application with one button and one imageview.
Once user clicks on the button camera is launched and after user selects picture it will be displayed with the proper orientation on the screen.
Add button named "TakePictureButton" and imageview named "TakenPictureImageView":
Once you add it to the project we can move on. Add below code which is responsible for launching camera. This method should be invoked in the button click as you can see in the above code:
voidtakePicture(){var picker =newMediaPicker(this);DateTime now = DateTime.Now;var intent = picker.GetTakePhotoUI(newStoreCameraMediaOptions{
Name ="picture_"+ now.Day +"_"+ now.Month +"_"+ now.Year +".jpg",
Directory =null});StartActivityForResult(intent,1);}
Once user takes picture we should display it in the proper orientation. To do it use below method. It is responsible for retrieveing exif information from the taken image (including orientation during the moment of taking picture) and than creating bitmap with the proper orientation: