protected void SetItemThumbnail(ImageBuffer thumbnail) { if (thumbnail != null) { // Resize canvas to target as fallback if (thumbnail.Width < thumbWidth || thumbnail.Height < thumbHeight) { thumbnail = ListView.ResizeCanvas(thumbnail, thumbWidth, thumbHeight); } else if (thumbnail.Width > thumbWidth || thumbnail.Height > thumbHeight) { thumbnail = LibraryProviderHelpers.ResizeImage(thumbnail, thumbWidth, thumbHeight); } if (GuiWidget.DeviceScale != 1) { thumbnail = thumbnail.CreateScaledImage(GuiWidget.DeviceScale); } // TODO: Resolve and implement // Allow the container to draw an overlay - use signal interface or add method to interface? //var iconWithOverlay = ActiveContainer.DrawOverlay() if (thumbnail != null && this.imageWidget != null && (this.imageWidget.Image == null || !thumbnail.Equals(this.imageWidget.Image, 5))) { this.imageWidget.Image = thumbnail; this.ImageSet?.Invoke(this, null); this.Invalidate(); } } }
public Task <ImageBuffer> GetThumbnail(ILibraryItem item, int width, int height) { return(Task.Run <ImageBuffer>(async() => { var thumbnail = await LoadImage(item); if (thumbnail != null) { thumbnail = LibraryProviderHelpers.ResizeImage(thumbnail, width, height); // Cache library thumbnail AggContext.ImageIO.SaveImageData( ApplicationController.Instance.Thumbnails.CachePath(item, width, height), thumbnail); } return thumbnail; })); }