Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Skija as a supported library #272

Closed
ebraminio opened this issue Jun 7, 2021 · 1 comment
Closed

Add Skija as a supported library #272

ebraminio opened this issue Jun 7, 2021 · 1 comment

Comments

@ebraminio
Copy link

ebraminio commented Jun 7, 2021

@file:DependsOn("org.jetbrains.kotlinx:kotlin-jupyter-lib-ext:0.10.0-40")
@file:Repository("https://packages.jetbrains.team/maven/p/skija/maven")
@file:DependsOn("org.jetbrains.skija:skija-macos-x64:0.92.0")

// Based on https://github.com/JetBrains/skija/blob/master/examples/bitmap/src/RenderToBitmap.java
import org.jetbrains.skija.*
import javax.imageio.ImageIO
import java.io.ByteArrayInputStream
import org.jetbrains.kotlinx.jupyter.ext.Image

val surface = Surface.makeRasterN32Premul(640, 360)
val canvas = surface.getCanvas()
canvas.clear(0xFFFFFFFF.toInt())
canvas.drawTriangles(
    arrayOf(Point(320f, 70f), Point(194f, 287f), Point(446f, 287f)),
    listOf(0xFF00FFFF, 0xFFFF00FF, 0xFFFFFF00).map { it.toInt() }.toIntArray(),
    Paint()
)
Image(ImageIO.read(ByteArrayInputStream(surface.makeImageSnapshot().encodeToData()?.getBytes())))

skija demo

This looks just great as is but maybe there can be tweaks you can add before having Skija listed in readme like providing some shorthand for image display or not.

tbh I wanted to file this so I won't lose this code and get some feedbacks so feel free to close this with no action as the situation looks just great as is. Thanks!

@ebraminio
Copy link
Author

So let's close this as no action was required from the beginning except a possibility to add to the list of supported which will be up to maintainers. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant