思路是先把图片读取到内存中,再转换成BitmapImage
代码:
string imgPath = "X:\\xxxxx.jpg"; var bytes = File.ReadAllBytes(imgPath); MemoryStream ms = new MemoryStream(bytes); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); imgHead.Source = bi;