public static void ReplacePreviewImage(WrapGrid area, PreviewArea preview, Picture pic) { using (Bitmap bitmap = new Bitmap(pic.Path)) { preview.SetImage(bitmap); preview.SetPictureInfo(pic.Name.GetText(), bitmap.Width, bitmap.Height); } area.GetArea().SetFocus(); }
public static void FillImageArea(CoreWindow handler, WrapGrid area, PreviewArea preview, String directory) { if (directory == null || directory == String.Empty) { return; } LoadingScreen screen = new LoadingScreen(); screen.Show(handler); Task thread = new Task(() => { area.Clear(); DirectoryInfo d = new DirectoryInfo(directory); FileInfo[] files = d.GetFiles(); List <Picture> list = new List <Picture>(); int count = files.Length; int index = 0; Parallel.ForEach(files, (f) => { index++; if (CheckExtensionFilter(f)) { Bitmap img = new Bitmap(f.FullName); Bitmap dBitmap = DownScaleBitmap(img, 170, 100); Picture pic = new Picture(dBitmap, f.Name, f.FullName); pic.EventMouseClick += (sender, args) => { ReplacePreviewImage(area, preview, pic); }; pic.EventKeyPress += (sender, args) => { if (args.Key == KeyCode.Enter) { ReplacePreviewImage(area, preview, pic); } }; dBitmap.Dispose(); img.Dispose(); list.Add(pic); } float persent = ((float)index / (float)count) * 100.0f; screen.SetValue((int)persent); }); if (list.Count == 0) { screen.SetToClose(); return; } list.Sort(); foreach (var item in list) { area.AddItem(item); } Random rnd = new Random(); int fileIndex = rnd.Next(0, list.Count); using (Bitmap img = new Bitmap(list[fileIndex].Path)) { preview.SetImage(img); preview.SetPictureInfo(new FileInfo(list[fileIndex].Path).Name, img.Width, img.Height); } screen.SetToClose(); }); thread.Start(); }