Пример #1
0
        public List <BitmapSource> Load(List <string> pathes,
                                        List <string> aviableFormats)
        {
            try
            {
                List <BitmapSource> pages = new List <BitmapSource>();

                UploadedFilesCountChanged?.Invoke(pathes.Count);
                int i = 0;
                pathes.Sort();

                foreach (var path in pathes)
                {
                    string ext = path.Substring(path.LastIndexOf('.'));

                    if (aviableFormats.Contains(ext))
                    {
                        BitmapImage page = new BitmapImage();
                        page.BeginInit();
                        page.CacheOption = BitmapCacheOption.OnLoad;
                        page.UriSource   = new Uri(path);
                        page.EndInit();
                        page.Freeze();
                        pages.Add(page);
                    }

                    UploadedFilesNumberChanged?.Invoke(++i);
                }

                return(pages);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public List <BitmapSource> Load(List <string> pathes,
                                        List <string> aviableFormats)
        {
            try
            {
                int entriesCount = 0;

                foreach (var path in pathes)
                {
                    using (Stream stream = File.OpenRead(path))
                        using (var reader = ReaderFactory.Open(stream))
                        {
                            while (reader.MoveToNextEntry())
                            {
                                entriesCount++;
                            }
                        }
                }

                UploadedFilesCountChanged?.Invoke(entriesCount);

                int i = 0;
                SortedList <string, BitmapSource> pages = new SortedList <string, BitmapSource>();

                foreach (var path in pathes)
                {
                    using (Stream stream = File.OpenRead(path))
                        using (var reader = ReaderFactory.Open(stream))
                        {
                            while (reader.MoveToNextEntry())
                            {
                                if (!reader.Entry.IsDirectory)
                                {
                                    string ext = reader.Entry.Key.Substring(
                                        reader.Entry.Key.LastIndexOf('.'));

                                    if (aviableFormats.Contains(ext))
                                    {
                                        using (MemoryStream ms = new MemoryStream((int)reader.Entry.Size))
                                        {
                                            reader.WriteEntryTo(ms);
                                            ms.Position = 0;
                                            BitmapImage page = new BitmapImage();
                                            page.BeginInit();
                                            page.StreamSource = ms;
                                            page.CacheOption  = BitmapCacheOption.OnLoad;
                                            page.EndInit();
                                            page.Freeze();
                                            pages.Add(reader.Entry.Key, page);
                                        }
                                    }
                                }

                                UploadedFilesNumberChanged?.Invoke(++i);
                            }
                        }
                }

                return(pages.Values.ToList());
            }
            catch (Exception)
            {
                throw;
            }
        }