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

  

posted @ 2020-12-08 14:00  人生为卒  阅读(211)  评论(0编辑  收藏  举报