blendColors function
Color
blendColors(
- Color? backgroundColor,
- Color foregroundColor
Implementation
Color blendColors(Color? backgroundColor, Color foregroundColor) {
if (backgroundColor == null) {
return foregroundColor;
}
double alpha = foregroundColor.a / 255.0;
double oneMinusAlpha = 1.0 - alpha;
int resultRed =
((oneMinusAlpha * backgroundColor.r) + (alpha * foregroundColor.r))
.round();
int resultGreen =
((oneMinusAlpha * backgroundColor.g) + (alpha * foregroundColor.g))
.round();
int resultBlue =
((oneMinusAlpha * backgroundColor.b) + (alpha * foregroundColor.b))
.round();
return ColorRgba8(resultRed, resultGreen, resultBlue, 255);
}