private static bool TryGetOrientation(string url, out Orientation rez)
 {
     try
     {
         var ei = new ExifInterface(url);
         rez = (Orientation)ei.GetAttributeInt(ExifInterface.TagOrientation, (int)Orientation.Normal);
         return(true);
     }
     catch
     {
         //nothing to do
     }
     rez = Orientation.Normal;
     return(false);
 }
Beispiel #2
0
 /**
  * Gets the Amount of Degress of rotation using the exif integer to determine how much
  * we should rotate the image.
  * @param exifOrientation - the Exif data for Image Orientation
  * @return - how much to rotate in degress
  */
 public static int ExifToDegrees(Orientation exifOrientation)
 {
     if (exifOrientation == Orientation.Rotate90)
     {
         return(90);
     }
     else if (exifOrientation == Orientation.Rotate180)
     {
         return(180);
     }
     else if (exifOrientation == Orientation.Rotate270)
     {
         return(270);
     }
     return(0);
 }
        //Background image
        public void LoadImage(string path, bool IsInResources, Abstractions.Scaling Scaling = Abstractions.Scaling.Absolute_None)
        {
            backgroundScaling = Scaling;
            if (IsInResources)
            {
                string file = path.Split('.')[0];
                var    id   = Resources.GetIdentifier(file.ToLower(), "drawable", Context.PackageName);
                backgroundBitmap = BitmapFactory.DecodeResource(Resources, id);
            }
            else
            {
                backgroundBitmap = BitmapFactory.DecodeFile(path);
                ExifInterface exif = new ExifInterface(path);
                var           orientationAttribute = exif.GetAttribute(ExifInterface.TagOrientation);

                Android.Media.Orientation orientationRotate = (Android.Media.Orientation) int.Parse(orientationAttribute);
                int imageRotation = 0;
                switch (orientationRotate)
                {
                case Android.Media.Orientation.Rotate90:
                    imageRotation = 90;
                    break;

                case Android.Media.Orientation.Rotate180:
                    imageRotation = 180;
                    break;

                case Android.Media.Orientation.Rotate270:
                    imageRotation = 270;
                    break;
                }

                imageSize.X      = backgroundBitmap.Width;
                imageSize.Y      = backgroundBitmap.Height;
                orientation      = imageRotation;
                backgroundBitmap = RotateBitmap(backgroundBitmap, imageRotation);
            }
        }