Skip to content

[Bug] Xamarin Android can't read EXIF data from the rotated image to check whether the image rotated or not #5687

@jeyakasipandi

Description

@jeyakasipandi

Description

To check whether the image is rotated or not by reading the EXIF meta data based on the orientation rotate then create the new bitmap and set to ImageView control.

[C#]

    protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            ImageView image = new ImageView(this);
            var bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.test);
            ExifInterface originalMetadata;
            using (var stream = new MemoryStream())
            {
                bitmap.Compress(Bitmap.CompressFormat.Jpeg, 0, stream);
                originalMetadata = new ExifInterface(stream);
            }

            int orientation = GetRotation(originalMetadata);

            Matrix matrix = new Matrix();
            if (orientation != 0)
            {
                matrix.PreRotate(orientation);
                bitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);
            }
            image.SetImageBitmap(bitmap);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
        }

Expected Behavior

To read the rotated image ExifData to get the orientation. Based on the orientation rotate then create the new bitmap and set to ImageView control.

Actual Behavior

Getting the ExifData orientation value as 0.

Basic Information

Tested device are Huawei PRA, Infinix Pro

Environment

Visual Studio 2019

Screenshots

[![enter image description here][1]][1]
image

Sample Link

ImageDemo.zip

Uploading Image_CameraAndGallery.zip…

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions