private BitmapImage DownloadImage(int numImages, int currentImage, Photo photo, string url) { BitmapImage image = new BitmapImage(); bool success = false; int numTries = 0; while (!success) { try { using (var client = new AwesomeWebClient()) { client.Proxy = null; var data = client.DownloadData(url); image = LoadImage(data); //var info = new MagickImageInfo(data); //PhotoCollection.Add(new DisplayPhoto(photo, image, new Uri(url), DefaultImageHeight, DefaultImageWidth)); //Console.WriteLine($"Downloaded photo {currentImage++} of {numImages}"); success = true; } } catch (Exception ex) { Console.WriteLine($"Download photo {currentImage} of {numImages} failed, trying again"); numTries++; if (numTries > 3) { //bail success = true; } } } return(image); }
private async void ShowPopup(object sender, RoutedEventArgs e) { //See this: https://www.zenfolio.com/zf/help/api/guide/download if (sender as Button != null && (sender as Button).DataContext != null) { ContactSheetPopup.IsOpen = true; Thumbnail.Visibility = Visibility.Hidden; LoadingImageStatusBar.Visibility = Visibility.Visible; //ContactSheetPopup.IsOpen = false; var photo = ((sender as Button).DataContext as DisplayPhoto).PhotoObject; int Size = 4; //800x630 var url = $"http://{photo.UrlHost}/{photo.UrlCore}-{Size}.jpg?sn={photo.Sequence}&tk={photo.UrlToken}"; var uri = new Uri(url); byte[] data; ExifProfile profile; using (var client = new AwesomeWebClient()) { client.Proxy = null; data = await client.DownloadDataTaskAsync(uri); var magickImage = new MagickImage(data); profile = magickImage.GetExifProfile(); } var imageUri = new Uri(url); //MagickImage magickImage = new MagickImage(new BitmapImage(imageUri).); Thumbnail.Source = LoadImage(data); LoadingImageStatusBar.Visibility = Visibility.Hidden; Thumbnail.Visibility = Visibility.Visible; Thumbnail.ToolTip = MakeTooltip(profile); //((BitmapSource)(Thumbnail.Source)).DownloadCompleted += ImageLoaded; //Thumbnail.Visibility = Visibility.Hidden; //LoadingImageStatusBar.Visibility = Visibility.Visible; ContactSheetPopup.IsOpen = true; } }