Question [Fonction] Eviter le verrouillage d'un fichier ressource (image) sous WPF

Plus d'informations
il y a 3 ans 1 mois #30614 par Laurent Dardenne
Une fonction de création de ressource image pour WPF, évite le verrouillage du fichier :
Function New-Bitmap {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions","",
   Justification="New-Bitmap function do not change the system state.")]
#Renvoi un bitmap n'utilisant pas de mise en cache
#Evite un verrou sur le fichier de ressource pointé par $Path
param(
                #Fichier de ressource
                [Parameter(Mandatory=$True)]
                [ValidateNotNullOrEmpty()]
                [string]  $Path
)
                $uriSource = [System.Uri]$Path
                $imgTemp = New-Object System.Windows.Media.Imaging.BitmapImage
                $imgTemp.BeginInit()
                $imgTemp.CacheOption = [System.Windows.Media.Imaging.BitmapCacheOption]::OnLoad
                $imgTemp.CreateOptions = [System.Windows.Media.Imaging.BitmapCreateOptions]::IgnoreImageCache
                $imgTemp.UriSource = $uriSource
                $imgTemp.EndInit()
                return $imgTemp
}
Exemple :
#Avant
$UI.window.Icon = $windowIcon #Chemin d'une image

#Après
$UI.window.Icon = New-BitMap $windowIcon

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.078 secondes
Propulsé par Kunena