Guest User

Untitled

a guest
Jun 8th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. private async void LoadImage_Async(Uri url)
  2. {
  3.  
  4.     // -- 1. загрузка и визуализация изображения - - - - - - - - - - - - - - - -
  5.     BitmapImage bi = new BitmapImage();
  6.     bi.BeginInit();
  7.     bi.CacheOption = BitmapCacheOption.OnLoad;
  8.     bi.UriSource = url;
  9.     bi.EndInit();
  10.  
  11.     while (bi.IsDownloading) // жду пока скачается
  12.     {
  13.         Debug.WriteLine($"bi Downloading: {bi.IsDownloading}");
  14.         await Task.Delay(100);
  15.     }
  16.     PreviewImage.Source = bi; // UI-элемент типа Image для визуализации изображения
  17.  
  18.  
  19.     // -- 2. загрузка и вывод метаданных изображения - - - - - - - - - - - - - - - -
  20.     BitmapSource bs = BitmapFrame.Create(url, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
  21.     while (bs.IsDownloading) // жду пока скачается
  22.     {
  23.         Debug.WriteLine($" bs Downloading: {bs.IsDownloading}");
  24.         await Task.Delay(100);
  25.     }
  26.     BitmapMetadata md = (BitmapMetadata)bs.Metadata;
  27.     MetadataInfo.Text = md?.Comment; // UI-элемент типа TextBox для вывода метаданных изображения
  28. }
Advertisement
Add Comment
Please, Sign In to add comment