fun Modifier.saturate(saturation: Float): Modifier = drawWithCache { // Cache the paint object so it can be reused between draw calls. val contentPaint = Paint().apply { colorFilter = ColorFilter.saturate(saturation) } onDrawWithContent { drawIntoCanvas { it.saveLayer(Rect(Offset.Zero, size), contentPaint) drawContent() it.restore() } } } fun ColorFilter.Companion.saturate(s: Float): ColorFilter { val saturationMatrix = floatArrayOf( .213f + .787f * s, .715f - .715f * s, .072f - .072f * s, 0f, 0f, .213f - .213f * s, .715f + .285f * s, .072f - .072f * s, 0f, 0f, .213f - .213f * s, .715f - .715f * s, .072f + .928f * s, 0f, 0f, 0f, 0f, 0f, 1f, 0f, ) return colorMatrix(ColorMatrix(saturationMatrix)) }