-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from michaldivis/vNext
v1.1.0
- Loading branch information
Showing
27 changed files
with
1,015 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using SkiaSharp.Views.Desktop; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace SampleApp; | ||
|
||
public static class BitmapUtils | ||
{ | ||
public static Color[] GetPixels(Bitmap bitmap) | ||
{ | ||
return bitmap.ToSKBitmap().Pixels | ||
.Select(x => x.ToDrawingColor()) | ||
.ToArray(); | ||
} | ||
|
||
public static BitmapImage BitmapToImageSource(Bitmap bitmap) | ||
{ | ||
using MemoryStream memory = new MemoryStream(); | ||
|
||
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); | ||
memory.Position = 0; | ||
BitmapImage bitmapimage = new BitmapImage(); | ||
bitmapimage.BeginInit(); | ||
bitmapimage.StreamSource = memory; | ||
bitmapimage.CacheOption = BitmapCacheOption.OnLoad; | ||
bitmapimage.EndInit(); | ||
|
||
return bitmapimage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using DarkColors; | ||
using System.Collections.ObjectModel; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace SampleApp; | ||
|
||
public partial class ColorAnalyzerExample : ObservableObject | ||
{ | ||
public class DemoImage | ||
{ | ||
public BitmapImage? BitmapSource { get; set; } | ||
public Color[] Pixels { get; set; } | ||
public ObservableCollection<DominantColorCandidate> Candidates { get; set; } = new(); | ||
} | ||
|
||
public DominantColorAnalyzerOptions Options { get; } = new() | ||
{ | ||
MaxCandidateCount = 5 | ||
}; | ||
|
||
public ObservableCollection<DemoImage> Images { get; } = new(); | ||
|
||
public ColorAnalyzerExample(Bitmap[] bitmaps) | ||
{ | ||
var images = bitmaps.Select(x => new DemoImage | ||
{ | ||
BitmapSource = BitmapUtils.BitmapToImageSource(x), | ||
Pixels = BitmapUtils.GetPixels(x) | ||
}); | ||
|
||
foreach (var image in images) | ||
{ | ||
Images.Add(image); | ||
} | ||
|
||
UpdateCandidates(); | ||
} | ||
|
||
[RelayCommand] | ||
private void UpdateCandidates() | ||
{ | ||
foreach (var result in Images) | ||
{ | ||
result.Candidates.Clear(); | ||
|
||
var candidates = ColorAnalyzer.FindDominantColors(result.Pixels, Options); | ||
|
||
foreach (var candidate in candidates) | ||
{ | ||
result.Candidates.Add(candidate); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.