getAverageColor static method
Implementation
static Color getAverageColor(Uint8List bytes) {
final image = img.decodeImage(bytes);
if (image == null) return Colors.black;
int r = 0;
int g = 0;
int b = 0;
int count = 0;
for (int y = 0; y < image.height; y += 10) {
for (int x = 0; x < image.width; x += 10) {
final pixel = image.getPixel(x, y);
r += pixel.r.toInt();
g += pixel.g.toInt();
b += pixel.b.toInt();
count++;
}
}
return Color.fromARGB(255, r ~/ count, g ~/ count, b ~/ count);
}