public override List <ImageFileContext> LoadImageFileContextList() { List <ImageFileContext> newList = new List <ImageFileContext>(); try { var pdfInfo = pdfDoc.GetInformation(); for (int i = 0; i < pdfDoc.PageCount; i++) { ImageFileContext ifc = new ImageFileContext($"{i+1:000}"); ImageFileInfo fi = new ImageFileInfo(); ifc.Info = fi; ifc.Archiver = this; fi.LastWriteTime = pdfInfo.ModificationDate; fi.Length = 0; newList.Add(ifc); } } catch { DisposeArchive(); Debug.WriteLine("LoadImageFileInfoList() failed path = " + ArchiverPath); } return(newList); }
public override List <ImageFileContext> LoadImageFileContextList() { // サブディレクトリを含める/含めない オプション SearchOption searchOpt; if (MainWindow.Current.Setting.SerachAllDirectoriesInFolderReading) { searchOpt = SearchOption.AllDirectories; } else { searchOpt = SearchOption.TopDirectoryOnly; } // フォルダ内のファイルパスを取得し、拡張子でフィルタ var imgPathes = Directory.GetFiles(this.ArchiverPath, "*.*", searchOpt); var filteredFiles = imgPathes.Where(file => AllowedFileExt.Any(ext => file.ToLower().EndsWith(ext))); // ロード List <ImageFileContext> newList = new List <ImageFileContext>(); foreach (string imgPath in filteredFiles) { ImageFileContext imageFileContext = new ImageFileContext(imgPath); imageFileContext.Archiver = this; newList.Add(imageFileContext); } return(newList); }
public override List <ImageFileContext> LoadImageFileContextList() { List <ImageFileContext> newList = new List <ImageFileContext>(); try { foreach (IArchiveEntry entry in archive.Entries) { // ファイル拡張子でフィルタ if (AllowedFileExt.Any(ext => entry.Key.ToLower().EndsWith(ext))) { // ロード ImageFileContext ifc = new ImageFileContext(entry.Key); ifc.Archiver = this; ImageFileInfo fi = new ImageFileInfo(); fi.LastWriteTime = entry.LastModifiedTime; fi.Length = entry.Size; ifc.Info = fi; newList.Add(ifc); } } } catch { DisposeArchive(); Debug.WriteLine("LoadImageFileInfoList() failed path = " + ArchiverPath); } return(newList); }
public override List <ImageFileContext> LoadImageFileContextList() { List <ImageFileContext> newList = new List <ImageFileContext>(); try { // エントリ var entries = GetEntries(); foreach (ZipArchiveEntry entory in entries) { // ファイル拡張子でフィルタ if (AllowedFileExt.Any(ext => entory.FullName.ToLower().EndsWith(ext))) { // ロード ImageFileContext ifc = new ImageFileContext(entory.FullName); ImageFileInfo fi = new ImageFileInfo(); ifc.Info = fi; ifc.Archiver = this; fi.LastWriteTime = entory.LastWriteTime; fi.Length = entory.Length; newList.Add(ifc); } } } catch { DisposeArchive(); Debug.WriteLine("LoadImageFileInfoList() failed path = " + ArchiverPath); } return(newList); }
public void LoadHistory(string path) { EnabledItemsInHistory ei = Setting.EnabledItemsInHistory; HistoryItem hi = Setting.History.FirstOrDefault(h => h.ArchiverPath == path); Profile pf = Setting.TempProfile; if (hi != null && (Directory.Exists(path) || File.Exists(path))) { // ファイル情報読み込み ReadFiles(new string[] { hi.ArchiverPath }, false); // 最後に読み込んだ画像(ページ番号) pf.LastPageIndex.Value = 0; if (hi.ImagePath != null) { ImageFileContext lastImageFileContext = ImgContainerManager.ImagePool.ImageFileContextList.FirstOrDefault(i => i.FilePath == hi.ImagePath); if (lastImageFileContext != null) { pf.LastPageIndex.Value = ImgContainerManager.ImagePool.ImageFileContextList.IndexOf(lastImageFileContext); } } // アス比 if (ei.AspectRatio && hi.AspectRatio != null) { Array.Copy(hi.AspectRatio, pf.AspectRatio.Value, pf.AspectRatio.Value.Length); } // 行列設定 if (ei.Matrix && hi.Matrix != null) { Array.Copy(hi.Matrix, pf.NumofMatrix.Value, pf.NumofMatrix.Value.Length); } // スライド方向 if (ei.SlideDirection && !(hi.SlideDirection == SlideDirection.None)) { pf.SlideDirection.Value = hi.SlideDirection; } // 見開きを検出するかどうか if (ei.DetectionOfSpread) { pf.DetectionOfSpread.Value = hi.DetectionOfSpread; } // 画像読み込み var t = ImgContainerManager.InitAllContainer(pf.LastPageIndex.Value); // ツールバー更新 UpdateToolbarViewing(); } else { NotificationBlock.Show(path + " は見つかりませんでした。", NotificationPriority.Normal, NotificationTime.Long, NotificationType.None); } }
public virtual void ReadInfoForView(ImageFileContext context) { using (Stream st = OpenStream(context.FilePath)) { try { ReadInfoForView(st, context); } catch { } } }
public ImageFileContext LoadImageFileContext(string filePath) { // 拡張子でフィルタ if (!AllowedFileExt.Any(ext => filePath.ToLower().EndsWith(ext))) { return(null); } ImageFileContext imageFileContext = new ImageFileContext(filePath); imageFileContext.Archiver = this; return(imageFileContext); }
public override void ReadInfoForView(ImageFileContext context) { // すでに取得済み if (context.Info.PixelSize != Size.Empty) { return; } // サイズ var size = pdfDoc.PageSizes[PathToPageIndex(context.FilePath)]; var side = MainWindow.Current.Setting.TempProfile.BitmapDecodeTotalPixel.Value; var maxSize = new Size(side, side); context.Info.PixelSize = new Size(size.Width, size.Height).StreachAsUniform(maxSize); }
public override Task <BitmapSource> LoadBitmap(Size bitmapDecodePixelMax, ImageFileContext context) { return(Task.Run(() => { if (context.IsDummy || context.FilePath == null || context.FilePath == "") { return null; } // 表示に必要な情報取得 ReadInfoForView(context); // BitmapDecodePixel値の決定 Size bitmapDecodePixel; if (bitmapDecodePixelMax != Size.Empty) { bitmapDecodePixel = context.Info.PixelSize.StreachAsUniform(bitmapDecodePixelMax).Round(); if (bitmapDecodePixel.Width > context.Info.PixelSize.Width) // 画像のサイズをオーバーする場合は、画像サイズをDecodePixelの値として指定する { bitmapDecodePixel = context.Info.PixelSize; } } else { bitmapDecodePixel = context.Info.PixelSize; } // Bitmap読み込み(System.Drawing.Image) var bitmap = pdfDoc.Render(PathToPageIndex(context.FilePath), (int)bitmapDecodePixel.Width, (int)bitmapDecodePixel.Height, 96, 96, false); // BitmapSourceに変換 using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage source = new BitmapImage(); source.BeginInit(); source.StreamSource = ms; source.CacheOption = BitmapCacheOption.OnLoad; source.CreateOptions = BitmapCreateOptions.None; source.EndInit(); source.Freeze(); Debug.WriteLine("bitmap load from pdf archiver: " + source.PixelWidth + "x" + source.PixelHeight + " path: " + context.FilePath + " refCnt: " + context.RefCount); return (BitmapSource)source; } })); }
/// <summary> /// スライド表示時に必要な、画像情報を取得(画像サイズとExif情報) /// </summary> protected virtual void ReadInfoForView(Stream st, ImageFileContext context) { // すでに取得済み if (context.Info.PixelSize != Size.Empty || context.Info.ExifInfo != ExifInfo.Empty) { return; } // ストリーム取得エラー if (st == Stream.Null) { return; } // メタデータ(Exif含む)取得 BitmapFrame bmf = BitmapFrame.Create(st); var metaData = (bmf.Metadata) as BitmapMetadata; //bmf.Freeze(); // ピクセルサイズ取得 st.Position = 0; try { context.Info.PixelSize = new Size(bmf.PixelWidth, bmf.PixelHeight); } catch { context.Info.PixelSize = new Size(); Debug.WriteLine("ReadImagePixelSize() is failed"); } // Exif情報取得 st.Position = 0; try { context.Info.ExifInfo = ReadExifInfoFromBitmapMetadata(metaData); } catch { context.Info.ExifInfo = new ExifInfo(); Debug.WriteLine("GetExifInfo() is failed"); } }
public ImageFileContext GetImageFileContextUnderCursor() { Border border = GetBorderUnderCursor(); if (border == null) { return(null); } ImgContainer parentContainer = WpfTreeUtil.FindAncestor <ImgContainer>(border); if (parentContainer == null) { return(null); } int idx = parentContainer.MainGrid.Children.IndexOf(border); ImageFileContext targetImgFileContext = parentContainer.ImageFileContextMapList[idx]; return(targetImgFileContext); }
public void OpenCurrentFolderByExplorer() { ImageFileContext ifc = ImgContainerManager.CurrentImageFileContext; string archiverPath; if (ifc == null) { return; } if (ifc.Archiver is NullArchiver) { archiverPath = Directory.GetParent(ifc.FilePath).FullName; } else { archiverPath = ifc.Archiver.ArchiverPath; } Process.Start("explorer.exe", "/select,\"" + archiverPath + "\""); }
public void DropNewSingleFileAsFolder(string path) { // 単体画像をフォルダとして読み込み string dirPath = Directory.GetParent(path).FullName; // 履歴にあるかチェック HistoryItem historyItem = Setting.History.FirstOrDefault(hi => hi.ArchiverPath == dirPath); // 一時的に「サブディレクトリ以下も読み込む」設定を、必ずOFFにする bool temp = Setting.SerachAllDirectoriesInFolderReading; Setting.SerachAllDirectoriesInFolderReading = false; // 履歴にあるなら、最後に開いた画像のパスを、ドロップしたファイルのパスに置き換える if (Setting.EnabledItemsInHistory.ArchiverPath && historyItem != null && Setting.ApplyHistoryInfoInNewArchiverReading) { historyItem.ImagePath = path; LoadHistory(dirPath); } // 履歴にない場合 else { ReadFiles(new string[] { dirPath }, false); ImageFileContext dropedFileInfo = ImgContainerManager.ImagePool.ImageFileContextList.FirstOrDefault(i => i.FilePath == path); int firstIndex; if (dropedFileInfo != null) { firstIndex = ImgContainerManager.ImagePool.ImageFileContextList.IndexOf(dropedFileInfo); } else { firstIndex = 0; } var t = ImgContainerManager.InitAllContainer(firstIndex); } // 「サブディレクトリ以下も読み込む」設定を復元 Setting.SerachAllDirectoriesInFolderReading = temp; }
public void SaveHistoryItem() { EnabledItemsInHistory ei = Setting.EnabledItemsInHistory; if (!ei.ImagePath && !ei.Matrix && !ei.SlideDirection) { return; } // アーカイバが1つの時だけ保存 if (ImgContainerManager.ImagePool.IsSingleArchiver && ImgContainerManager.ImagePool.Archivers[0].LeaveHistory) { HistoryItem hi = Setting.History.FirstOrDefault(h => h.ArchiverPath == ImgContainerManager.ImagePool.Archivers[0].ArchiverPath); if (hi != null) { // 最後に読み込んだ画像のパス(並び順に依らないページ番号復元用) ImageFileContext ifc = ImgContainerManager.CurrentImageFileContext; if (ifc != null) { hi.ImagePath = ifc.FilePath; } else { hi.ImagePath = ""; } // アス比 hi.AspectRatio = new int[] { Setting.TempProfile.AspectRatio.H, Setting.TempProfile.AspectRatio.V }; // 行列 hi.Matrix = new int[] { Setting.TempProfile.NumofMatrix.Col, Setting.TempProfile.NumofMatrix.Row }; // スライド方向 hi.SlideDirection = Setting.TempProfile.SlideDirection.Value; // 見開きを検出するかどうか hi.DetectionOfSpread = Setting.TempProfile.DetectionOfSpread.Value; } } }
public void Execute() { Profile pf = MainWindow.Current.Setting.TempProfile; // 履歴保存 MainWindow.Current.SaveHistoryItem(); // 現在のコンテキスト ImageFileContext ifc = MainWindow.Current.ImgContainerManager.CurrentImageFileContext; // フォルダ(書庫)のパス string archiverPath; if (ifc != null) { if (ifc.Archiver is Archiver.NullArchiver) { archiverPath = Directory.GetParent(ifc.FilePath).FullName; } else { archiverPath = ifc.Archiver.ArchiverPath; } } else { // TempProfileから取得 if (pf.Path.Value.Count == 0) { return; } var cand = pf.Path.Value[0]; if (Archiver.ArchiverBase.IsReadablePath(cand)) { archiverPath = cand; } else { return; } } // 親フォルダ取得 string parentFolderPath; try { parentFolderPath = Directory.GetParent(archiverPath).FullName; } catch { return; } // 親フォルダ内のフォルダ・ファイル一覧 var candidates = Directory.GetDirectories(parentFolderPath).ToList(); candidates.AddRange(Directory.GetFiles(parentFolderPath).ToList()); // 順番取得 var currentPath = candidates.FirstOrDefault(c => c == archiverPath); if (currentPath == null) { return; } var currentIndex = candidates.IndexOf(currentPath); // 次のフォルダ(書庫)を取得 int cnt = 0; string nextPath = ""; int nextIndex = currentIndex; while (cnt < candidates.Count) { // 取得 nextIndex++; if (nextIndex >= candidates.Count) { nextIndex = 0; } nextPath = candidates[nextIndex]; // チェック if (nextPath == currentPath) { nextPath = ""; break; } // 1周して見つからず else if (Archiver.ArchiverBase.IsReadablePath(nextPath)) { break; } // 対応可能な書庫orフォルダ cnt++; } // 通知 string message; if (nextPath == "" || nextPath == currentPath) { message = "次のフォルダ(書庫)がありません"; } else { string arc = Directory.Exists(nextPath) ? "フォルダ" : "書庫"; message = "次の" + arc + ": " + Path.GetFileName(nextPath); } MainWindow.Current.NotificationBlock.Show(message, NotificationPriority.Normal, NotificationTime.Normal, NotificationType.None); MainWindow.Current.Refresh(); // 読み込み if (nextPath != "" && nextPath != currentPath) { MainWindow.Current.DropNewFiles(new string[] { nextPath }); } return; }
// @ref https://chitoku.jp/programming/wpf-lazy-image-behavior public virtual Task <BitmapSource> LoadBitmap(Size bitmapDecodePixelMax, ImageFileContext context) { return(Task.Run(() => { if (context.IsDummy || context.FilePath == null || context.FilePath == "") { return null; } using (Stream st = OpenStream(context.FilePath)) { try { // 表示に必要な情報取得 ReadInfoForView(st, context); // BitmapImage(BitmapSource)用意 var source = new BitmapImage(); source.BeginInit(); source.CacheOption = BitmapCacheOption.OnLoad; source.CreateOptions = BitmapCreateOptions.None; // DecodePixel値の決定 if (bitmapDecodePixelMax != Size.Empty) { Size bitmapDecodePixel = context.Info.PixelSize.StreachAsUniform(bitmapDecodePixelMax).Round(); if (bitmapDecodePixel.Width > context.Info.PixelSize.Width) // 画像のサイズをオーバーする場合は、画像サイズをDecodePixelの値として指定する { source.DecodePixelWidth = (int)context.Info.PixelSize.Width; } else { source.DecodePixelWidth = (int)bitmapDecodePixel.Width; } } // 読み込み source.StreamSource = st; // 回転 if (MainWindow.Current.Setting.TempProfile.ApplyRotateInfoFromExif.Value) { source.Rotation = context.Info.ExifInfo.Rotation; } // 読み込み終了処理 source.EndInit(); source.Freeze(); // Exifに反転もあった場合は、BitmapImage.Rotationで対応出来ないのでTransform if (source != null && MainWindow.Current.Setting.TempProfile.ApplyRotateInfoFromExif.Value && context.Info.ExifInfo.ScaleTransform != null) { return TransformBitmap(source, context.Info.ExifInfo.ScaleTransform); } Debug.WriteLine("bitmap load from archiver: " + source.PixelWidth + "x" + source.PixelHeight + " path: " + context.FilePath + " refCnt: " + context.RefCount); return (BitmapSource)source; } catch { return null; } } })); }
public void Execute() { MainWindow mw = MainWindow.Current; // カーソル下のタイル取得 //Tile targetTile = mw.GetBorderUnderCursor(); // カーソル下の画像情報、Border取得 ImageFileContext ifc = mw.GetImageFileContextUnderCursor(); Border border = mw.GetBorderUnderCursor(); // 取得失敗 if (ifc == null) { return; } // ダミーだった場合 if (ifc != null && ifc.IsDummy) { return; } // コンテキストメニューのClosedイベント完了を待つ if (!closedEventFinished) { int cnt = 0; while (!closedEventFinished) { DoEvents(); System.Threading.Thread.Sleep(10); cnt++; if (cnt > 50) { closedEventFinished = true; return; } } } // コンテキストメニュー作成 ContextMenu contextMenu = new ContextMenu(); // タイルを強調表示(拡大時はしない) bool IsExpanded = MainWindow.Current.TileExpantionPanel.IsShowing; if (!IsExpanded) { HighlightTargetTile(border); closedEventFinished = false; contextMenu.Closed += (se, ev) => { border.BorderBrush = new SolidColorBrush(mw.Setting.TempProfile.GridLineColor.Value); border.BorderThickness = new Thickness(mw.Setting.TempProfile.TilePadding.Value); closedEventFinished = true; }; } // ツールチップ string toolTip_CopyFile = "コピー後、エクスプローラーで貼り付けが出来ます"; string toolTip_CopyFileData = "コピー後、ペイント等の画像編集ソフトへ貼り付けが出来ます"; string toolTip_FilePath; if (ifc.Archiver.CanReadFile) { toolTip_FilePath = ifc.FilePath; } else { toolTip_FilePath = ifc.Archiver.ArchiverPath; } string toolTip_FileName = System.IO.Path.GetFileName(ifc.FilePath); // メニューアイテム作成 if (!IsExpanded) { contextMenu.Items.Add(CreateMenuItem("拡大表示", null, (s, e) => { var t = mw.TileExpantionPanel.Show(border); })); contextMenu.Items.Add(new Separator()); } else { contextMenu.Items.Add(CreateMenuItem("拡大表示を終了", null, (s, e) => { mw.TileExpantionPanel.Hide(); })); contextMenu.Items.Add(new Separator()); } int num = 0; foreach (var exAppInfo in MainWindow.Current.Setting.ExternalAppInfoList) { if (exAppInfo.ShowContextMenu) { string name = exAppInfo.GetAppName(); if (name != null) { contextMenu.Items.Add(CreateMenuItem(name + "で開く", null, (s, e) => { ifc.OpenByExternalApp(exAppInfo); })); num++; } } } if (num > 0) { contextMenu.Items.Add(new Separator()); } contextMenu.Items.Add(CreateMenuItem("ファイルをコピー", toolTip_CopyFile, (s, e) => { ifc.CopyFile(); })); contextMenu.Items.Add(CreateMenuItem("画像データをコピー", toolTip_CopyFileData, (s, e) => { var t = ifc.CopyImageData(); })); contextMenu.Items.Add(CreateMenuItem("ファイルパスをコピー", toolTip_FilePath, (s, e) => { ifc.CopyFilePath(); })); contextMenu.Items.Add(CreateMenuItem("ファイル名をコピー", toolTip_FileName, (s, e) => { ifc.CopyFileName(); })); if (!IsExpanded) { contextMenu.Items.Add(new Separator()); contextMenu.Items.Add(CreateMenuItem("画像1枚分ずらし進める", null, (s, e) => { mw.ShortcutManager.ExecuteCommand(CommandID.ShiftForward, 1, null); })); contextMenu.Items.Add(CreateMenuItem("画像1枚分ずらし戻す", null, (s, e) => { mw.ShortcutManager.ExecuteCommand(CommandID.ShiftBackward, 1, null); })); } // コンテキストメニュー表示 contextMenu.IsOpen = true; // スライド再生中だったら止める if (!IsExpanded && mw.IsPlaying) { mw.ImgContainerManager.StopSlideShow(false); contextMenu.Closed += (s, e) => { mw.ImgContainerManager.StartSlideShow(false); }; } return; }