Exemple #1
0
        public static void ProceedSelectedImage(Android.Net.Uri uri)
        {
            var path = uri.Path.StartsWith("file://") ? uri.Path : uri.GetRealPathFromUri(CrossCurrentActivity.Current.AppContext);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            var fileName   = System.IO.Path.GetFileNameWithoutExtension(path);
            var ext        = System.IO.Path.GetExtension(path) ?? string.Empty;
            var thumbImage = ImageHelpers.RotateImage(path, 0.25f);

            var thumbnailImagePath =
                MediaFileHelper.GetOutputPath(MediaFileType.Image, "TmpMedia",
                                              $"{fileName}-THUMBNAIL{ext}");

            File.WriteAllBytes(thumbnailImagePath, thumbImage);

            var mediaFile = new MediaFile
            {
                Path        = path,
                PreviewPath = thumbnailImagePath,
                Type        = MediaFileType.Image
            };

            MediaChooser.Current.Success?.Invoke(new List <MediaFile> {
                mediaFile
            });
        }
Exemple #2
0
        public IActionResult Get()
        {
            var basePath      = config.MediaFilesBasePath;
            var mediasPaths   = this.client.ListFilePathsByExtension(this.config.MediaFilesBasePath, "mpd");
            var relativePaths = mediasPaths.Select(mp => MediaFileHelper.RemoveBasePath(mp, basePath))
                                .Where(rl => !string.IsNullOrEmpty(rl));

            return(JsonResultHelper.Parse(relativePaths, HttpStatusCode.OK));
        }
Exemple #3
0
        public void Should_RemoveBasePath()
        {
            var fullPath = "/content/rapaziada.mpd";
            var basePath = "/content";
            var expected = "/rapaziada.mpd";

            var result = MediaFileHelper.RemoveBasePath(fullPath, basePath);

            Assert.AreEqual(expected, result);
        }
Exemple #4
0
        public static string CreatePreviewPath(string path, string type)
        {
            var fileName   = System.IO.Path.GetFileNameWithoutExtension(path);
            var ext        = System.IO.Path.GetExtension(path) ?? string.Empty;
            var thumbImage = ImageHelpers.RotateImage(path, 0.25f);

            var thumbnailImagePath =
                MediaFileHelper.GetOutputPath(MediaFileType.Image, "TmpMedia",
                                              $"{fileName}-THUMBNAIL{ext}");

            File.WriteAllBytes(thumbnailImagePath, thumbImage);

            return(thumbnailImagePath);
        }
        private async void FinishedPickingAssets(object sender, MultiAssetEventArgs args)
        {
            var results = new List <MediaFile>(24);
            var tcs     = new TaskCompletionSource <IList <MediaFile> >();

            Debug.WriteLine("User finished picking assets. {0} items selected.", args.Assets.Length);

            _preselectedAssets = args.Assets;

            // For demo purposes: just show all chosen pictures in order every second
            foreach (var asset in _preselectedAssets)
            {
                // Get information about the asset, e.g. file patch
                asset.RequestContentEditingInput(new PHContentEditingInputRequestOptions(),
                                                 completionHandler: (input, options) =>
                {
                    var path = input.FullSizeImageUrl.ToString();
                    path     = path.Replace("file://", "");

                    var fileName        = System.IO.Path.GetFileNameWithoutExtension(path);
                    var ext             = System.IO.Path.GetExtension(path);
                    var imgOption       = MediaFileGetImageOptions.CreateDefaultThumb();
                    var thumbImageBytes = AssetImageService.GetImageBytes(asset, imgOption);

                    var thumbnailImagePath =
                        MediaFileHelper.GetOutputPath(MediaFileType.Image, "TmpMedia",
                                                      $"{fileName}-THUMBNAIL{ext}");
                    System.IO.File.WriteAllBytes(thumbnailImagePath, thumbImageBytes);

                    results.Add(new MediaFile
                    {
                        Path        = path,
                        PreviewPath = thumbnailImagePath,
                        Type        = MediaFileType.Image
                    });
                });

                await Task.Delay(250);
            }

            tcs.TrySetResult(results);
            _mediaPickTcs?.TrySetResult(await tcs.Task);
            _preselectedAssets = null;
        }
        public async Task <string> CreatePreviewPath(string path, string type)
        {
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            var fileName = System.IO.Path.GetFileNameWithoutExtension(path);
            var ext      = System.IO.Path.GetExtension(path);

            var strs        = path.Split('/');
            var assetResult = PHAsset.FetchAssetsUsingLocalIdentifiers(strs, null);
            var asset       = assetResult.firstObject as PHAsset;

            var thumbImageBytes =
                AssetImageService.GetImageBytes(asset, MediaFileGetImageOptions.CreateDefaultThumb());

            var thumbnailImagePath =
                MediaFileHelper.GetOutputPath(MediaFileType.Image, "TmpMedia",
                                              $"{fileName}-THUMBNAIL{ext}");

            System.IO.File.WriteAllBytes(thumbnailImagePath, thumbImageBytes);

            return(thumbnailImagePath);
        }