DevBase.Avalonia
1.2.6
dotnet add package DevBase.Avalonia --version 1.2.6
NuGet\Install-Package DevBase.Avalonia -Version 1.2.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DevBase.Avalonia" Version="1.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DevBase.Avalonia" Version="1.2.6" />
<PackageReference Include="DevBase.Avalonia" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DevBase.Avalonia --version 1.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DevBase.Avalonia, 1.2.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DevBase.Avalonia@1.2.6
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DevBase.Avalonia&version=1.2.6
#tool nuget:?package=DevBase.Avalonia&version=1.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DevBase.Avalonia
DevBase.Avalonia provides color analysis and image processing utilities for Avalonia UI applications. It specializes in extracting dominant colors, calculating color clusters, and analyzing image properties.
Features
- Color Extraction - Extract dominant colors from images
- Cluster Analysis - Group similar colors using clustering algorithms
- Brightness Calculation - Find brightest colors in images
- Color Utilities - Color manipulation and conversion helpers
- Avalonia Integration - Works seamlessly with Avalonia UI bitmaps
Installation
dotnet add package DevBase.Avalonia
Core Components
Color Calculators
BrightestColorCalculator- Finds the brightest color in an imageGroupColorCalculator- Groups similar colors togetherNearestColorCalculator- Finds nearest color to a target
Extensions
ColorExtension- Color manipulation methodsColorNormalizerExtension- Color normalization utilitiesLockedFramebufferExtensions- Direct pixel access helpers
Utilities
ColorUtils- General color utility methods
Quick Start
Extract Brightest Color
using Avalonia.Media.Imaging;
using DevBase.Avalonia.Color.Image;
var bitmap = new Bitmap("image.png");
var calculator = new BrightestColorCalculator();
var brightestColor = calculator.Calculate(bitmap);
Console.WriteLine($"Brightest color: {brightestColor}");
Group Similar Colors
using DevBase.Avalonia.Color.Image;
var calculator = new GroupColorCalculator();
var colorGroups = calculator.Calculate(bitmap);
foreach (var group in colorGroups)
{
Console.WriteLine($"Group: {group.Key}, Count: {group.Value}");
}
Find Nearest Color
using DevBase.Avalonia.Color.Image;
using Avalonia.Media;
var calculator = new NearestColorCalculator();
var targetColor = Colors.Blue;
var nearestColor = calculator.FindNearest(bitmap, targetColor);
Console.WriteLine($"Nearest to blue: {nearestColor}");
Usage Examples
Album Art Color Analysis
using Avalonia.Media.Imaging;
using DevBase.Avalonia.Color.Image;
public class AlbumArtAnalyzer
{
public Color GetDominantColor(string imagePath)
{
var bitmap = new Bitmap(imagePath);
var calculator = new BrightestColorCalculator();
return calculator.Calculate(bitmap);
}
public List<Color> GetColorPalette(string imagePath, int colorCount)
{
var bitmap = new Bitmap(imagePath);
var calculator = new GroupColorCalculator();
var groups = calculator.Calculate(bitmap);
return groups.Keys.Take(colorCount).ToList();
}
}
UI Theme Generation
public class ThemeGenerator
{
public (Color Primary, Color Accent) GenerateTheme(Bitmap image)
{
var brightest = new BrightestColorCalculator().Calculate(image);
var groups = new GroupColorCalculator().Calculate(image);
var primary = brightest;
var accent = groups.Keys.FirstOrDefault(c => c != primary);
return (primary, accent);
}
}
Color Extensions
using DevBase.Avalonia.Color.Extensions;
using Avalonia.Media;
var color = Colors.Red;
// Normalize color
var normalized = color.Normalize();
// Convert to different format
var converted = color.ToHsl();
// Adjust brightness
var brighter = color.AdjustBrightness(1.2);
Integration with Avalonia UI
Window Background Color
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using DevBase.Avalonia.Color.Image;
public class DynamicWindow : Window
{
public void SetBackgroundFromImage(string imagePath)
{
var bitmap = new Bitmap(imagePath);
var calculator = new BrightestColorCalculator();
var dominantColor = calculator.Calculate(bitmap);
this.Background = new SolidColorBrush(dominantColor);
}
}
Control Theming
public class ThemedControl : UserControl
{
public void ApplyImageTheme(Bitmap image)
{
var calculator = new GroupColorCalculator();
var colors = calculator.Calculate(image);
var primary = colors.Keys.First();
var secondary = colors.Keys.Skip(1).First();
// Apply to controls
this.Foreground = new SolidColorBrush(primary);
this.BorderBrush = new SolidColorBrush(secondary);
}
}
Data Structures
ClusterData
public class ClusterData
{
public Color CenterColor { get; set; }
public List<Color> Colors { get; set; }
public int Count { get; set; }
}
Performance Considerations
- Image Size - Larger images take longer to process
- Color Depth - More unique colors increase processing time
- Caching - Cache results for frequently analyzed images
- Async Processing - Consider async for large images
Common Use Cases
Use Case 1: Music Player UI
public class MusicPlayer
{
public void UpdateUIFromAlbumArt(Bitmap albumArt)
{
var calculator = new BrightestColorCalculator();
var dominantColor = calculator.Calculate(albumArt);
// Update player UI colors
playerBackground.Background = new SolidColorBrush(dominantColor);
progressBar.Foreground = new SolidColorBrush(dominantColor);
}
}
Use Case 2: Image Gallery
public class ImageGallery
{
public void GenerateThumbnailColors(List<string> imagePaths)
{
var calculator = new BrightestColorCalculator();
foreach (var path in imagePaths)
{
var bitmap = new Bitmap(path);
var color = calculator.Calculate(bitmap);
// Store color for thumbnail border
thumbnailColors[path] = color;
}
}
}
Use Case 3: Adaptive UI
public class AdaptiveUI
{
public void AdaptToImage(Bitmap image)
{
var groups = new GroupColorCalculator().Calculate(image);
var brightest = new BrightestColorCalculator().Calculate(image);
// Determine if image is light or dark
bool isLight = CalculateBrightness(brightest) > 0.5;
// Adjust UI accordingly
if (isLight)
{
textColor = Colors.Black;
backgroundColor = Colors.White;
}
else
{
textColor = Colors.White;
backgroundColor = Colors.Black;
}
}
}
Target Framework
- .NET 9.0
- Avalonia UI 11.x
Dependencies
- Avalonia - UI framework
- Avalonia.Media - Color and imaging
- DevBase - Core utilities
License
MIT License - See LICENSE file for details
Author
AlexanderDotH
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Avalonia (>= 11.3.10)
- DevBase (>= 1.3.5)
- DevBase.Cryptography (>= 1.0.6)
- System.Drawing.Common (>= 10.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DevBase.Avalonia:
| Package | Downloads |
|---|---|
|
DevBase.Avalonia.Extension
A high performance image color extractor based on image clusterization |
GitHub repositories
This package is not used by any popular GitHub repositories.