Forum Xamarin.Android

ExifInterface always returning rotation 0

ArvindrajaArvindraja INMember ✭✭✭

Hii all,
i'm detecting image rotation in my app while i'm browsing images from gallery, ExifInterface always returning 0 so image rotation unable to detect. this is my code in OnActivityResult
var imgV = FindViewById<ImageView>(Resource.Id.imageView1); base.OnActivityResult(requestCode, resultCode, data); if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null)) { Android.Net.Uri uri = data.Data; b = null; b = MediaStore.Images.Media.GetBitmap(ContentResolver, uri); File f = new File(uri.Path); ExifInterface exif = new ExifInterface(uri.Path); int orientation2 = exif.GetAttributeInt(ExifInterface.TagOrientation, 90); int exifOrientation = exif.GetAttributeInt( ExifInterface.TagOrientation, (int)Android.Media.Orientation.Normal); int rotate = 0; switch (exifOrientation) { case (int)Android.Media.Orientation.Rotate90: rotate = 90; break; case (int)Android.Media.Orientation.Rotate180: rotate = 180; break; case (int)Android.Media.Orientation.Rotate270: rotate = 270; break; } if (rotate != 0) { b = MediaStore.Images.Media.GetBitmap(ContentResolver, uri); int w = b.Width; int h = b.Height; matrix = new Matrix(); matrix.PostRotate(rotate); Bitmap scaledBitmap = Bitmap.CreateScaledBitmap(b, 300, 300, true); b = Bitmap.CreateBitmap(b, 0, 0, w, h, matrix, false); ImageView imageView = (ImageView)FindViewById(Resource.Id.imageView1); imageView.SetImageBitmap(b); } else { b = MediaStore.Images.Media.GetBitmap(ContentResolver, uri); Bitmap scaledBitmap = Bitmap.CreateScaledBitmap(b, 300, 300, true); matrix = new Matrix(); w = b.Width; h = b.Height; b = Bitmap.CreateBitmap(b, 0, 0, b.Width, b.Height, matrix, false); ImageView imageView = (ImageView)FindViewById(Resource.Id.imageView1); imageView.SetImageBitmap(b); } }
this is my code, where is the problem i don't know. i'm using the Samsung S3 mobile images, please help thank you :)

Sign In or Register to comment.