private void LoadFileOrDirectory(string path) { // 新規アーカイバ ArchiverBase archiver; // ファイル if (File.Exists(path)) { // 拡張子取得 string ext = Path.GetExtension(path); // 画像ファイル単体 ImageFileContext ifc = NullArchiver.LoadImageFileContext(path); if (ifc != null) { ImageFileContextList.Add(ifc); } // 圧縮ファイル / その他のファイル else { if (ext == ".lnk") { // .lnkファイルの場合、ショートカット先のフルパスを取得し、やり直し LoadFileOrDirectory(GetShortcutTargetPath(path)); return; } else { // 書庫 archiver = ArchiverFactory.Create(path, ext); if (archiver == null) { return; } else { Archivers.Add(archiver); } } ImageFileContextList.AddRange(archiver.LoadImageFileContextList()); } } // フォルダ else if (Directory.Exists(path)) { Archivers.Add(archiver = new FolderArchiver(path)); ImageFileContextList.AddRange(archiver.LoadImageFileContextList()); } }
public ImageFileContext PickForward() { ImageFileContext context = ImageFileContextList[ForwardIndex]; ImageFileContextList[ForwardIndex].RefCount++; ForwardIndex++; if (ForwardIndex >= ImageFileContextList.Count) { ForwardIndex = 0; } return(context); }
public ImageFileContext PickBackward() { ImageFileContext context = ImageFileContextList[BackwardIndex]; ImageFileContextList[BackwardIndex].RefCount++; BackwardIndex--; if (BackwardIndex < 0) { BackwardIndex = ImageFileContextList.Count - 1; } return(context); }
public async Task LoadImage(CancellationToken token) { for (int i = 0; i < MainGrid.Children.Count; i++) { if (token.IsCancellationRequested) { break; // キャンセルがリクエストされた } var child = MainGrid.Children[i]; Border border = child as Border; Image image = border.Child as Image; ImageFileContext mapedImageFileContext = ImageFileContextMapList[i]; if (border == null || image == null || mapedImageFileContext == null) { continue; } if (i < ImageFileContextMapList.Count) { if (mapedImageFileContext.BitmapImage == null) { // 新たにファイルから読み込み Debug.WriteLine("BitmapImage = null : " + mapedImageFileContext.FilePath); var source = await ImageFileContextMapList[i].LoadBitmap(BitmapDecodePixelOfTile); mapedImageFileContext.BitmapImage = (BitmapImage)source; if (!token.IsCancellationRequested) { image.Source = source; } else { Debug.WriteLine("BitmapImgae loaded and canceled by Task cancellation request"); } } else if (image.Source != mapedImageFileContext.BitmapImage) { // すでにあるBitmapImageを利用 System.Diagnostics.Debug.WriteLine("BitmapImage = exist! : " + mapedImageFileContext.FilePath + " Size: " + mapedImageFileContext.BitmapImage.PixelWidth + "x" + mapedImageFileContext.BitmapImage.PixelHeight); image.Source = mapedImageFileContext.BitmapImage; } } } }