Beispiel #1
0
        BitmapSource TryGetImage(string uriString, InternalImageOptions options)
        {
            if (uriString == null)
            {
                return(null);
            }

            var           key = new ImageKey(uriString, options);
            WeakReference weakImage;
            BitmapSource  image;

            if (imageCache.TryGetValue(key, out weakImage))
            {
                image = weakImage.Target as BitmapSource;
                if (image != null)
                {
                    return(image);
                }
            }

            image = TryLoadImage(uriString, options.PhysicalSize);
            if (image == null)
            {
                return(null);
            }

            if (options.BackgroundColor != null)
            {
                image = ThemedImageCreator.CreateThemedBitmapSource(image, options.BackgroundColor.Value, isHighContrast);
            }
            imageCache[key] = new WeakReference(image);
            return(image);
        }
Beispiel #2
0
        BitmapSource GetImageUsingUri(string uri, Color bgColor)
        {
            var          key = Tuple.Create(uri, bgColor);
            BitmapSource image;

            if (imageCache.TryGetValue(key, out image))
            {
                return(image);
            }

            image = ThemedImageCreator.CreateThemedBitmapSource(new BitmapImage(new Uri(uri)), bgColor, isHighContrast);
            imageCache.Add(key, image);
            return(image);
        }