WPF中Image控件的Source属性的设置

1、直接关联到文件,关联后不能删除此图片,因为图片正在使用。

imageEditImage.Source = new BitmapImage(new Uri(strImagePath, UriKind.Absolute));//strImagePath 就绝对路径

2、转成二进制,与图片原文件脱离

var img = new BitmapImage();
            img.BeginInit();
            img.StreamSource = new MemoryStream(File.ReadAllBytes(path));
            img.EndInit();

img.Source = img ;
原文地址:https://www.cnblogs.com/lunawzh/p/6694082.html