BitmapImage in WPF does lock file

前端 未结 4 642
自闭症患者
自闭症患者 2020-11-27 22:34

I use:

Dim bmi As New BitmapImage(New Uri(fiInfo.FullName, UriKind.Absolute))
bmi.CacheOption = BitmapCacheOption.OnLoad

this does not Use

4条回答
  •  忘掉有多难
    2020-11-27 23:29

    Read the BitmapImage from file and rewrite it with a MemoryStream:

    MemoryStream ms = new MemoryStream();
    BitmapImage bi = new BitmapImage();
    byte[] bytArray = File.ReadAllBytes(@"test.jpg");
    ms.Write(bytArray, 0, bytArray.Length);ms.Position = 0;
    bi.BeginInit();
    bi.StreamSource = ms;
    bi.EndInit();
    image.Source = bi;
    

提交回复
热议问题