Skip to content

Commit

Permalink
(#75) Fix potential failure in GetColor crashing the album display
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Jun 15, 2023
1 parent 596f8c4 commit 99045fd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/Stylophone.Common/Helpers/ColorThief.Skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public QuantizedColor GetColor(SKBitmap sourceImage, int quality = DefaultQualit
{
var palette = GetPalette(sourceImage, 3, quality, ignoreWhite);

// Handle case where GetPalette returns an empty list (because GetColorMap failed?)
if (palette.Count == 0)
{
return new QuantizedColor(SKColors.Black, 1);
}

var avgR = Convert.ToByte(palette.Average(a => a.Color.Red));
var avgG = Convert.ToByte(palette.Average(a => a.Color.Green));
var avgB = Convert.ToByte(palette.Average(a => a.Color.Blue));
Expand Down

0 comments on commit 99045fd

Please sign in to comment.