Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> ConcatenateAsync(ImageOptions options)
        {
            var fileName         = options.ConcatenatedImageFileNameScheme.Invoke(this);
            var filePath         = Path.Combine(options.ConcatenatedImageDirectory, fileName);
            var filePhysicalPath = Path.Combine(options.RootDirectory, filePath).Replace('/', Path.DirectorySeparatorChar);

            Path.GetDirectoryName(filePhysicalPath).CreateDirectory();

            if (!File.Exists(filePhysicalPath))
            {
                var fileAbsolutePaths = ImagePaths
                                        .Where(_ => !_.IsNullOrWhiteSpace())
                                        .Select(_ => _.PreProcess(options.RootDirectory))
                                        .ToList();
                var fileImage = (await ImageHelper.FromFileOrNetworkAsync(fileAbsolutePaths[0]))?.Resize(Width, Height);
                foreach (var path in fileAbsolutePaths.Skip(1))
                {
                    using var image = await ImageHelper.FromFileOrNetworkAsync(path);

                    if (image == null)
                    {
                        continue;
                    }

                    fileImage = fileImage.Concatenate(image.Resize(Width, Height));
                }

                using (fileImage)
                    fileImage.CompressSave(filePhysicalPath, options.CompressFlag, ImageFormat.Jpeg);
            }

            return(filePath);
        }
Ejemplo n.º 2
0
 private void ImagePaths_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (ImagePaths.Count(i => !string.IsNullOrEmpty(i)) > 0)
     {
         if (ImagePaths.Count(i => !string.IsNullOrEmpty(i)) > _photosBase64Dictionary.Count)
         {
             var fileProvider = DependencyService.Get <IFileSystemWork>();
             foreach (
                 var newPhotoPath in ImagePaths.Where(path => _photosBase64Dictionary.All(b64 => b64.Key != path)))
             {
                 if (!newPhotoPath.Contains("http://185.76.145.214/") && !string.IsNullOrEmpty(newPhotoPath))
                 {
                     var tempBase64Photo = Convert.ToBase64String(fileProvider.GetFile(newPhotoPath));
                     _photosBase64Dictionary.Add(newPhotoPath, tempBase64Photo);
                     PhotosBase64Dictionary.Add(tempBase64Photo);
                 }
                 else if (!string.IsNullOrEmpty(newPhotoPath))
                 {
                     _photosBase64Dictionary.Add(newPhotoPath, newPhotoPath);
                     PhotosBase64Dictionary.Add(newPhotoPath);
                 }
             }
         }
         else if (ImagePaths.Count(i => !string.IsNullOrEmpty(i)) < _photosBase64Dictionary.Count)
         {
             var tempToRemove = _photosBase64Dictionary.Where(b64 => !ImagePaths.Contains(b64.Key))
                                .Select(b64 => b64.Key);
             foreach (var itemToDelete in tempToRemove)
             {
                 PhotosBase64Dictionary.Remove(_photosBase64Dictionary.First(i => i.Key == itemToDelete).Value);
                 _photosBase64Dictionary.Remove(itemToDelete);
             }
         }
     }
     else
     {
         _photosBase64Dictionary.Clear();
         PhotosBase64Dictionary.Clear();
     }
 }