Norbi
10/20/2023, 9:50 AMCsaba Kozák
10/20/2023, 10:53 AMMichael Paus
10/20/2023, 11:12 AMCsaba Kozák
10/20/2023, 11:21 AMandroid.graphics.Picture
class.Michael Paus
10/20/2023, 11:26 AMimport androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.*
import java.io.File
import javax.imageio.ImageIO
import kotlin.test.Test
import kotlin.test.assertTrue
class ImageCanvasTest {
@Test
fun test() {
val image = ImageBitmap(400, 400)
val canvas = Canvas(image)
canvas.drawLine(Offset.Zero, Offset(image.width.toFloat(), image.height.toFloat()), Paint().apply { color = Color.Red })
val file = File("canvasimage.png")
if (file.exists()) file.delete()
ImageIO.write(image.toAwtImage(), "png", file)
assertTrue(file.exists())
}
}
Marcin Wisniowski
10/23/2023, 2:06 PMBox { Image(); Text("Watermark")... }
to use a Compose layout to add a watermark to an image (not that it’s a great use case, but a simple example).
Not using Canvas, just composable layouts that would then be rendered to an image, instead of to a screen.