Load a large BitmapImage asynchronously

前端 未结 1 848
有刺的猬
有刺的猬 2020-12-16 08:17

I\'m trying to load a very large image (about 16000x7000 pixel) into a Material, and I\'ve tried to load it asynchronously. My first try was to create a task that loaded the

相关标签:
1条回答
  • 2020-12-16 08:49

    I'm not sure about this asynchronous scenario, but you would usually set BitmapCacheOption.OnLoad to force immediate caching to memory:

    var bmp = await System.Threading.Tasks.Task.Run(() => 
    { 
        BitmapImage img = new BitmapImage(); 
        img.BeginInit(); 
        img.CacheOption = BitmapCacheOption.OnLoad; 
        img.UriSource = new Uri(path); 
        img.EndInit(); 
        ImageBrush brush = new ImageBrush(img); 
        ...
    }
    
    0 讨论(0)
提交回复
热议问题