WPF img.Source赋值不占用文件
img.Source = this.GetBitmapImage(m_picCtlData.NewPicPath);//imageControl为WPF Image控件
/// <summary>
/// 复制文件,不占用文件
/// </summary>
/// <param name="imagePath"></param>
/// <returns></returns>
public BitmapImage GetBitmapImage(string imagePath)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.UriSource = new Uri(imagePath);
bitmap.EndInit();
return bitmap.Clone();
}
浙公网安备 33010602011771号