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();
        }

  

原文地址:https://www.cnblogs.com/lhlong/p/14102293.html