Пример #1
0
        async Task <IReadOnlyDictionary <string, object> > PortableAsyncRenderer <Bitmap> .GetAttributesAsync
        (
            PortableCorrelatedEntity correlatedEntity,
            Func <string> correlationTag
        )
        {
            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            IReadOnlyDictionary <string, string> imageAttributes
                = await AndroidExifHandler.GetPictureAttributesAsync
                  (
                      FilePath,
                      attributeTags : new[]
            {
                ExifInterface.TagOrientation,
                ExifInterface.TagModel,
                ExifInterface.TagDatetimeDigitized,

                ExifInterface.TagDatetime,
                ExifInterface.TagGpsAltitude,
                ExifInterface.TagGpsAltitudeRef,
                ExifInterface.TagGpsLatitude,
                ExifInterface.TagGpsLatitudeRef,
                ExifInterface.TagGpsLongitude,
                ExifInterface.TagGpsLongitudeRef
            }
                  );

            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            var objectAttributes = new Dictionary <string, object>
                                   (
                imageAttributes.Count
                                   );

            foreach (KeyValuePair <string, string> imageAttribute in imageAttributes)
            {
                string attributeKey = imageAttribute.Key;

                object attributeValue = imageAttribute.Value;

                objectAttributes.Add(attributeKey,
                                     attributeValue);
            }

            return(objectAttributes);
        }
Пример #2
0
        public static async Task <Bitmap> GetThumbnailAsync
        (
            this PortableCorrelatedEntity correlatedEntity,
            Func <string> correlationTag,
            int viewWidth,
            int viewHeight,
            //Bitmap reusedThumbnail,
            string thumbnailPath
        )
        {
            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            int pictureOrientation = await AndroidExifHandler.GetPictureOrientationAsync
                                     (
                thumbnailPath
                                     );

            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            byte[] thumbnailData = await AndroidExifHandler.GetThumbnailDataAsync(thumbnailPath);

            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            Bitmap thumbnailBitmap = await AndroidBitmapHandler.LoadAdjustedBitmapAsync
                                     (
                thumbnailPath,
                viewWidth,
                viewHeight,
                pictureOrientation,
                //reusedThumbnail,
                thumbnailData
                                     );

            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                thumbnailBitmap?.Dispose();
                thumbnailBitmap = null;
            }

            return(thumbnailBitmap);
        }
Пример #3
0
        private async void RotateImage
        (
            object sender,
            EventArgs arguments
        )
        {
            int pictureOrientation = await AndroidExifHandler.GetPictureOrientationAsync(_picturePath);

            pictureOrientation = (pictureOrientation + 90) % 360;

            await AndroidExifHandler.SetPictureOrientationAsync(_picturePath,
                                                                pictureOrientation);

            LoadImageAsync();
        }
Пример #4
0
        private async void LoadImageAsync()
        {
            if (_deviceOrientation == null)
            {
                _deviceOrientation = Intent.GetIntExtra(DeviceOrientationExtra,
                                                        OrientationEventListener.OrientationUnknown);
            }

            if (_deviceOrientation == OrientationEventListener.OrientationUnknown)
            {
                _deviceOrientation = 0;
            }

            // http://stackoverflow.com/questions/20902775/how-to-check-if-auto-rotate-screen-setting-is-on-off-in-android-4-0
            bool autoRotation = (Settings.System.GetInt(ContentResolver,
                                                        Settings.System.AccelerometerRotation, 0) == 1);

            int pictureOrientation = await AndroidExifHandler.GetPictureOrientationAsync(_picturePath);

            if (autoRotation == false)
            {
                pictureOrientation += (360 - _deviceOrientation.Value) % 360;
            }

            int viewWidth  = _imageView.Width;
            int viewHeight = _imageView.Height;

            DisplayMetrics displayMetrics = Resources.DisplayMetrics;
            double         displayWidth   = displayMetrics.WidthPixels;
            var            displayHeight  = displayMetrics.HeightPixels;

            Size bitmapSize = await AndroidBitmapHandler.GetBitmapSizeAsync(_picturePath);

            int imageWidth  = bitmapSize.Width;
            int imageHeight = bitmapSize.Height;

            // when auto-rotation switched off, image view rectangle may be 'wrongly rotated' for
            // the image width / height as saved (without taking picture rotation flag into account):
            if ((autoRotation == false) ||
                ((displayWidth - displayHeight) * (imageWidth - imageHeight) < 0))
            {
                viewWidth  = _imageView.Height;
                viewHeight = _imageView.Width;
            }

            Bitmap imageBitmap = null;
            CorruptObjectException imageException = null;

            try
            {
                // resize the bitmap to fit the display - loading the full sized image will consume too much memory:
                imageBitmap = await AndroidBitmapHandler.LoadAdjustedBitmapAsync
                              (
                    _picturePath,
                    viewWidth,
                    viewHeight,
                    pictureOrientation
                              );
            }
            catch (Exception exception)
            {
                imageException = exception as CorruptObjectException;

                if (imageException == null)
                {
                    throw;
                }
            }

            RunOnUiThread
            (
                () =>

            {
                if (imageException != null)
                {
                    this.HandleCorruptObject(imageException,
                                             _imageView);
                }
                else
                {
                    using (imageBitmap)
                    {
                        _imageView.SetImageBitmap(imageBitmap);
                    }

                    imageBitmap = null;

                    _attributesButton.Visibility = ViewStates.Visible;
                    _rotateButton.Visibility     = ViewStates.Visible;
                }
            }
            );
        }