Jonathan
03/24/2025, 7:39 PMJonathan
03/24/2025, 7:41 PMfun Modifier.hueRotate(degrees: Float): Modifier =
this.drawWithCache {
val hueMatrix = createHueRotationMatrix(degrees)
val colorFilter = ColorFilter.colorMatrix(hueMatrix)
onDrawWithContent {
drawContent()
drawRect(
color = Color.Transparent,
topLeft = Offset.Zero,
size = size,
colorFilter = colorFilter
)
}
}
But because of the Color.Transparent it doesn’t seem to work.Sergey Y.
03/24/2025, 7:58 PMromainguy
03/24/2025, 8:00 PMromainguy
03/24/2025, 8:00 PMromainguy
03/24/2025, 8:01 PMromainguy
03/24/2025, 8:01 PMJonathan
03/24/2025, 8:01 PMromainguy
03/24/2025, 8:01 PMromainguy
03/24/2025, 8:02 PM.graphicsLayer(
colorFilter = LightingColorFilter(Color.White, Color.Red)
)
romainguy
03/24/2025, 8:02 PMJonathan
03/24/2025, 8:02 PMromainguy
03/24/2025, 8:02 PMJonathan
03/24/2025, 8:05 PMromainguy
03/24/2025, 8:05 PMromainguy
03/24/2025, 8:06 PMromainguy
03/24/2025, 8:06 PMSergey Y.
03/24/2025, 8:17 PMYou can either use Canvas.saveWithLayer (or equivalent) or use a graphicsLayer set to offscreen compositing@romainguy Is there any performance difference between canvas.saveWithLayer and graphicsLayer with the offscreen composition strategy, or are these equivalent operations but through different APIs?
romainguy
03/24/2025, 8:24 PMJonathan
03/24/2025, 8:25 PMJonathan
03/24/2025, 8:26 PMgraphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
.drawWithCache {
val hueMatrix = createHueRotationMatrix(degrees)
val colorFilter = ColorFilter.colorMatrix(hueMatrix)
onDrawWithContent {
drawContent()
drawRect(
color = Color.Transparent,
colorFilter = colorFilter,
)
}
}
doesn’t work a well.Jonathan
03/24/2025, 8:27 PMSergey Y.
03/24/2025, 8:28 PMJonathan
03/24/2025, 8:28 PMSergey Y.
03/24/2025, 8:33 PMI’d like to create a generic Modifier that allows me to apply any a custom color matrix to any composable.Do you need to create some sort of color filter modifier? This sounds exactly like what I did with the desaturation modifier in my code example. Or am I missing something?
Jonathan
03/24/2025, 8:33 PMJonathan
03/24/2025, 8:48 PMval saturationMatrix = ColorMatrix().apply { setToSaturation(amount) }
val saturationFilter = ColorFilter.colorMatrix(saturationMatrix)
Is there any performance gain using your solution?Sergey Y.
03/24/2025, 8:49 PMromainguy
03/24/2025, 9:10 PMromainguy
03/24/2025, 9:11 PMromainguy
03/24/2025, 9:14 PMromainguy
03/24/2025, 9:14 PMSergey Y.
03/24/2025, 9:15 PMJonathan
03/24/2025, 9:15 PMromainguy
03/24/2025, 9:15 PMromainguy
03/24/2025, 9:16 PMromainguy
03/24/2025, 9:17 PMromainguy
03/24/2025, 9:19 PMSergey Y.
03/24/2025, 9:19 PMromainguy
03/24/2025, 9:32 PMromainguy
03/24/2025, 9:36 PMJonathan
03/24/2025, 9:37 PM