darken method
Change each pixel's color to be darker and return a new Image.
The amount
is a double value between 0 and 1.
Implementation
Future<Image> darken(double amount) async {
assert(amount >= 0 && amount <= 1);
final pixelData = await pixelsInUint8();
final newPixelData = Uint8List(pixelData.length);
for (var i = 0; i < pixelData.length; i += 4) {
final color = Color.fromARGB(
pixelData[i + 3],
pixelData[i + 0],
pixelData[i + 1],
pixelData[i + 2],
).darken(amount);
newPixelData[i] = color.red;
newPixelData[i + 1] = color.green;
newPixelData[i + 2] = color.blue;
newPixelData[i + 3] = color.alpha;
}
return fromPixels(newPixelData, width, height);
}