Esempio n. 1
0
        /// <summary>
        /// Gets the picture media file.
        /// </summary>
        /// <param name="info">The information.</param>
        /// <returns>MediaFile.</returns>
        private MediaFile GetPictureMediaFile(NSDictionary info)
        {
            var image = (UIImage)info[UIImagePickerController.EditedImage];

            if (image == null)
            {
                image = (UIImage)info[UIImagePickerController.OriginalImage];
            }

            var path = GetOutputPath(
                MediaPicker.TypeImage,
                _options.Directory ?? ((IsCaptured) ? String.Empty : "temp"),
                _options.Name);

            using (var fs = File.OpenWrite(path))
                using (Stream s = new NsDataStream(image.AsJPEG()))
                {
                    s.CopyTo(fs);
                    fs.Flush();
                }

            Action <bool> dispose = null;

            if (_source != UIImagePickerControllerSourceType.Camera)
            {
                dispose = d => File.Delete(path);
            }

            return(new MediaFile(path, () => File.OpenRead(path), dispose));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the picture media file.
        /// </summary>
        /// <param name="info">The information about captured media.</param>
        /// <returns>The media file representing the captured media.</returns>
        private MediaFile GetPictureMediaFile(NSDictionary info)
        {
            // Get the image data
            var image = (UIImage)info[UIImagePickerController.EditedImage]
                        ?? (UIImage)info[UIImagePickerController.OriginalImage];

            // Get the output path
            var path = MediaPickerDelegate.GetOutputPath(
                MediaPickerIOS.TypeImage,
                this.options.Directory ?? (this.IsCapture ? string.Empty : "temp"),
                this.options.Name);

            // Write image as JPEG
            using (var fs = File.OpenWrite(path))
            {
                using (Stream s = new NsDataStream(image.AsJPEG()))
                {
                    s.CopyTo(fs);
                    fs.Flush();
                }
            }

            // Create the media file instance
            Action <bool> dispose = null;

            if (this.source != UIImagePickerControllerSourceType.Camera)
            {
                dispose = d => File.Delete(path);
            }

            // Return the captured media
            return(new MediaFile(path, () => File.OpenRead(path), dispose));
        }
Esempio n. 3
0
        private void GetPictureMediaFileWithMetadata(NSDictionary metadataIn, UIImage image, Action <MediaFile> callback)
        {
            var metadata = new NSMutableDictionary(metadataIn);

            if (_options.MaxPixelDimension.HasValue)
            {
                float w = 0, h = 0;
                float coeff = Math.Max((float)image.Size.Width, (float)image.Size.Height) / (float)_options.MaxPixelDimension.Value;
                w     = (float)image.Size.Width / coeff;
                h     = (float)image.Size.Height / coeff;
                image = MaxResizeImage(image, w, h);
                image = RotateImage(image, metadata);
            }

            //image = RotateImage(image, metadata);

            var path = GetOutputPath(
                MediaPicker.TypeImage,
                _options.Directory ?? ((IsCaptured) ? String.Empty : "temp"),
                _options.Name);

            var compress = _options.PercentQuality.HasValue ? _options.PercentQuality.Value / 100f : 1f;

            var data = GetDataWriteMetadata(image, metadata, compress);

            using (var fs = File.OpenWrite(path))
                using (Stream s = new NsDataStream(data))
                {
                    s.CopyTo(fs);
                    fs.Flush();
                }

            Action <bool> dispose = null;

            if (_source != UIImagePickerControllerSourceType.Camera)
            {
                dispose = d => File.Delete(path);
            }

            var mf = new MediaFile(path, () => File.OpenRead(path), dispose);

            callback(mf);
        }