I have a pure powershell script with WPF and XAML GUI. There is an Image loaded like $WPFImage.Source='C:..\1.png' when I change the Source to another picture, it shows the other picture properly. But the first picture is still locked. Unfortunately the Image control has no Dispose method. Any idea how to close the open handle/filestream?
Asked
Active
Viewed 165 times
-1
-
1https://stackoverflow.com/q/29625428/1136211, https://stackoverflow.com/q/12799931/1136211, not sure if you can make use of it in PowerShell. – Clemens Mar 31 '23 at 22:19
1 Answers
0
[Edit] Figured it out, no special XAML necessary, pure Powershell Solution:
$img = New-Object System.Windows.Media.Imaging.BitmapImage
$img.BeginInit()
$img.UriSource = "C:\temp\Screenshots\1.png"
$img.CacheOption = [System.Windows.Media.Imaging.BitmapCacheOption]::OnLoad
$img.EndInit()
$img.Freeze()
$WPFimg.Source=$img
Thank you Clemens for comment.

christoph.mue
- 71
- 12