Example #1
0
        private async void GetCachedBitmapAsync()
        {
            isWaiting = true;
            WaitCompleted?.Invoke(this, EventArgs.Empty);

            var s = mediaId.ToString();

            if (PictureCache.HasPicture(s))
            {
                var entry = PictureCache.GetPicture(s);

                if (Thumbnail && entry.OriginalPicture.IsThumbnailAvailable)
                {
                    await entry.GetThumbnailAsync();

                    Image = entry.XamlThumbnailBitmap;
                }
                else
                {
                    await entry.GetFullSizeAsync();

                    Image = entry.XamlFullSizeBitmap;
                }
            }
            else
            {
                Image = new BitmapImage(ResourceUriHelper.BuildUri("DefaultArtwork.png"));
                Log.Warning(nameof(CacheImageSource), $"No picture cache entry for {s}");
            }

            isWaiting = false;
            WaitCompleted?.Invoke(this, EventArgs.Empty);
        }
Example #2
0
        private static async void MediaIdPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var _this  = (CachedImage)dependencyObject;
            var _value = (string)dependencyPropertyChangedEventArgs.NewValue;

            if (PictureCache.HasPicture(_value))
            {
                var entry = PictureCache.GetPicture(_value);
                if (_this.RenderSize.Width > ThumbnailSize || _this.RenderSize.Height > ThumbnailSize)
                {
                    await entry.GetFullSizeAsync();

                    _this.MainImage.Source = entry.XamlFullSizeBitmap;
                }
                else
                {
                    if (entry.OriginalPicture.IsThumbnailAvailable)
                    {
                        await entry.GetThumbnailAsync();

                        _this.MainImage.Source = entry.XamlThumbnailBitmap;
                    }
                    else
                    {
                        await entry.GetFullSizeAsync();

                        _this.MainImage.Source = entry.XamlFullSizeBitmap;
                    }
                }
            }
            else
            {
                _this.MainImage.Source = new BitmapImage(ResourceUriHelper.BuildUri("DefaultArtwork.png"));
                Log.Warning(nameof(CachedImage), $"No picture cache entry for {_value}");
            }
        }