Skip to content

画像読み込み時のファイルハンドル保持問題を修正#205

Merged
Freeesia merged 2 commits into
masterfrom
copilot/fix-file-handle-issue
May 2, 2026
Merged

画像読み込み時のファイルハンドル保持問題を修正#205
Freeesia merged 2 commits into
masterfrom
copilot/fix-file-handle-issue

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor

WPF がファイルパス文字列を ImageSource に型変換する際、デフォルト動作ではファイルハンドルを保持し続けるため、設定済み画像の削除・移動・上書きができなかった。

変更内容

  • FilePathToImageSourceConverter を追加 (OverlayWindow.xaml.cs)
    BitmapCacheOption.OnLoad で読み込み後即座にファイルハンドルを解放。Freeze() でスレッドセーフ化。壊れたファイルや非対応形式は null を返して安全に処理。

    bitmap.BeginInit();
    bitmap.UriSource = new Uri(path, UriKind.Absolute);
    bitmap.CacheOption = BitmapCacheOption.OnLoad; // 読み込み後にファイルハンドルを解放
    bitmap.EndInit();
    bitmap.Freeze();
  • XAML バインディングを更新(4箇所)
    OverlayWindow.xamlMainWindow.xaml(2箇所)・DesktopCatalog.xamlSource="{Binding ImagePath}" をすべてコンバーター経由に変更。

Copilot AI changed the title [WIP] Fix issue with holding file handle when setting image 画像読み込み時のファイルハンドル保持問題を修正 May 1, 2026
Copilot AI requested a review from Freeesia May 1, 2026 17:40
@Freeesia Freeesia marked this pull request as ready for review May 2, 2026 05:09
@Freeesia Freeesia merged commit 3bf4e7c into master May 2, 2026
6 checks passed
@Freeesia Freeesia deleted the copilot/fix-file-handle-issue branch May 2, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

画像を設定するとファイルハンドルを握り続けてしまう

2 participants