spierce7
06/14/2022, 9:54 PMromainguy
06/14/2022, 10:04 PMspierce7
06/14/2022, 10:09 PMcreate an ALPHA_8 bitmap, create a Canvas for it, draw your original image into itHow would I do this? I’ve never heard of an Alpha 8 bitmap
create a Canvas for it
Is this an Android Canvas? Technically I’m doing this on Compose DesktopKirill Grouchnikov
06/14/2022, 11:13 PMspierce7
06/14/2022, 11:35 PMval svgPainter: Painter
val shader = Shader.makeFractalNoise(
baseFrequencyX = 8.21f,
baseFrequencyY = 8.21f,
numOctaves = 3,
seed = 0.0f,
)
val shaderBrush = ShaderBrush(shader)
Canvas(
modifier = Modifier.size(width = maxWidth.dp, height = maxHeight.dp)
) {
drawRect(shaderBrush)
}
I’m not understanding how this all comes together. I want to use the shader as a mask so that I can draw the svgPainter
where the shaderBrush
draws something.BlendMode
and it sounds like it could work, but there aren’t a ton of examples of this online.romainguy
06/14/2022, 11:38 PMspierce7
06/14/2022, 11:40 PMBut the equivalent of Paint.setShader will use a bitmap as an alpha maskSo both Skia
Paint
and androidx Paint
look like there is a setShader
method. How does the bitmap come into play?Painter
to a bitmap or drawn on the canvas.val shader = Shader.makeFractalNoise(
baseFrequencyX = 8.21f,
baseFrequencyY = 8.21f,
numOctaves = 3,
seed = 0.0f,
)
val shaderBrush = ShaderBrush(shader)
val svgSize = Size(width = maxWidth.toFloat(), height = maxHeight.toFloat())
Canvas(
modifier = Modifier.size(width = maxWidth.dp, height = maxHeight.dp)
) {
drawRect(shaderBrush, size = svgSize)
with(svgPainter) {
draw(size = svgSize)
}
}
romainguy
06/15/2022, 12:05 AMspierce7
06/15/2022, 12:05 AMromainguy
06/15/2022, 12:11 AMspierce7
06/15/2022, 12:14 AMromainguy
06/15/2022, 12:42 AMspierce7
06/15/2022, 12:42 AMromainguy
06/15/2022, 12:43 AMDST_IN
(or CLEAR
but I don’t remember if CLEAR
modulates by alpha)spierce7
06/15/2022, 12:43 AMval bitmap = ImageBitmap(width = width, height = height, config = ImageBitmapConfig.Alpha8)
.also { bitmap ->
val canvas = Canvas(bitmap)
val shaderBrush = ShaderBrush(
Shader.makeFractalNoise(
baseFrequencyX = 8.21f,
baseFrequencyY = 8.21f,
numOctaves = 3,
seed = 0.0f,
)
)
val svgSize = Size(width = width.toFloat(), height = height.toFloat())
CanvasDrawScope().draw(LocalDensity.current, LayoutDirection.Ltr, canvas, svgSize) {
with(painter) {
draw(size = svgSize)
}
drawRect(brush = shaderBrush, size = svgSize, blendMode = BlendMode.DstIn)
}
}
romainguy
06/15/2022, 12:44 AMALPHA_8
bitmapspierce7
06/15/2022, 12:45 AMArgb8888
Stylianos Gakis
06/15/2022, 6:14 AM