47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Chrosey.Extensions
|
|
{
|
|
public static class ImageExtensions
|
|
{
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste an Farben zurück, die für ein Quantisierungsverfahren geeignet sind.
|
|
/// </summary>
|
|
/// <param name="bitmap"></param>
|
|
/// <returns></returns>
|
|
public static List<Color> Pixels(this Bitmap bitmap, int quality)
|
|
{
|
|
|
|
var pixels = new List<Color>();
|
|
var count = 0;
|
|
for (int x = 0; x < bitmap.Width; x++)
|
|
{
|
|
for (int y = 0; y < bitmap.Height; y++)
|
|
{
|
|
if (count % quality == 0)
|
|
{
|
|
count = 0;
|
|
var p = bitmap.GetPixel(x, y);
|
|
if (p.A >= 125)
|
|
{
|
|
if (!(p.R > 250 && p.G > 250 && p.B > 250))
|
|
{
|
|
pixels.Add(p.SignificantColor());
|
|
}
|
|
}
|
|
}
|
|
|
|
count++;
|
|
}
|
|
}
|
|
return pixels;
|
|
}
|
|
}
|
|
}
|