Пример #1
0
        private static void DoLoadImage(IHasImageButton hasImageButton, string location)
        {
            try {
                if (CardImageCache.ContainsKey(hasImageButton.Name))
                {
                    hasImageButton.Image = CardImageCache[hasImageButton.Name];
                    CropImage(hasImageButton);
                    return;
                }

                var uri = new Uri(location, UriKind.Absolute);
                if (uri.IsFile)
                {
                    var localImage = ImageUtils.LoadLocalImage(uri);
                    hasImageButton.Image = localImage;
                    CardImageCache[hasImageButton.Name] = localImage;
                    CropImage(hasImageButton);
                }
                else
                {
                    var bitmapImage = new BitmapImage(uri);
                    bitmapImage.DownloadCompleted += (s, e) => {
                        CardImageCache[hasImageButton.Name] = bitmapImage;
                        CropImage(hasImageButton);
                    };
                    hasImageButton.Image = bitmapImage;
                }
            } catch {
                //todo: add logging, which means changing this from an extention method into a service
            }
        }
Пример #2
0
 internal static void CropImage(IHasImageButton hasImageButton)
 {
     try {
         hasImageButton.ButtonImage        = hasImageButton.Image.CropImage(hasImageButton.ImageCardType);
         hasImageButton.ButtonImageAsBytes = hasImageButton.ButtonImage.AsBytes();
     } catch {
         //todo: add logging, which means changing this from an extention method into a service
     }
 }
Пример #3
0
 public static void LoadImage(this IHasImageButton hasImageButton, string url)
 {
     if (Application.Current.Dispatcher.CheckAccess())
     {
         DoLoadImage(hasImageButton, url);
     }
     else
     {
         Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => {
             DoLoadImage(hasImageButton, url);
         }));
     }
 }
        public void LoadImage(IHasImageButton hasImageButton)
        {
            if (string.IsNullOrEmpty(hasImageButton.ImageSource))
            {
                return;
            }

            if (Application.Current.Dispatcher.CheckAccess())
            {
                DoLoadImage(hasImageButton);
            }
            else
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => {
                    DoLoadImage(hasImageButton);
                }));
            }
        }
        private void DoLoadImage(IHasImageButton hasImageButton)
        {
            try {
                _logger.LogMessage($"Loading image for button {hasImageButton.Name}");

                if (_cache.IsInCache(hasImageButton.ImageId))
                {
                    _logger.LogMessage($"Found image in cache for button {hasImageButton.Name}");
                    hasImageButton.Image = _cache.GetFromCache(hasImageButton.ImageId);
                    if (hasImageButton.Image is BitmapImage bitmapImage && bitmapImage.IsDownloading)
                    {
                        bitmapImage.DownloadCompleted += (s, e) => {
                            CropImage(hasImageButton);
                        };
                    }
                    else
                    {
                        CropImage(hasImageButton);
                    }
                    return;
                }

                var uri = new Uri(hasImageButton.ImageSource, UriKind.Absolute);
                if (uri.IsFile)
                {
                    var localImage = ImageUtils.LoadLocalImage(uri);
                    hasImageButton.Image = localImage;
                    _cache.SaveTocache(hasImageButton.ImageId, localImage);
                    CropImage(hasImageButton);
                }
                else
                {
                    var bitmapImage = new BitmapImage(uri);
                    _cache.SaveTocache(hasImageButton.ImageId, bitmapImage);
                    bitmapImage.DownloadCompleted += (s, e) => {
                        CropImage(hasImageButton);
                    };
                    hasImageButton.Image = bitmapImage;
                }
            } catch (Exception ex) {