27. LINE Creators Studio ❤ Kotlin
Why Kotlin?
val color = Color.CYAN
val alpha = (color shr 24) and 0xff
val red = (color shr 16) and 0xff
val green = (color shr 8) and 0xff
val blue = (color ) and 0xff
28. LINE Creators Studio ❤ Kotlin
Why Kotlin?
inline val @receiver:ColorInt Int.alpha get() = (this shr 24) and 0xff
inline val @receiver:ColorInt Int.red get() = (this shr 16) and 0xff
inline val @receiver:ColorInt Int.green get() = (this shr 8) and 0xff
inline val @receiver:ColorInt Int.blue get() = (this ) and 0xff
29. LINE Creators Studio ❤ Kotlin
Why Kotlin?
val a = color.alpha
val r = color.red
val g = color.green
val b = color.blue
30. LINE Creators Studio ❤ Kotlin
Why Kotlin?
inline operator fun @receiver:ColorInt Int.component1() = this.alpha
inline operator fun @receiver:ColorInt Int.component2() = this.red
inline operator fun @receiver:ColorInt Int.component3() = this.green
inline operator fun @receiver:ColorInt Int.component4() = this.blue
32. LINE Creators Studio ❤ Kotlin
Why Kotlin?
https://developer.android.com/kotlin/ktx
/ J / Ii P / X
/ r P / ae c t K
/ IplJ / I a ec k ed ed
I r P / P / o I I
P
/ I / n P J KAT
Android KTX
33. LINE Creators Studio ❤ Kotlin
Creators Studio Extensions for
OpenCV
val bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888)
val mat = Mat()
Utils.bitmapToMat(bitmap, mat)
val newBitmap = Bitmap.createBitmap(mat.width(), mat.height(),
Bitmap.Config.ARGB_8888)
Utils.matToBitmap(mat, newBitmap)
34. LINE Creators Studio ❤ Kotlin
Creators Studio Extensions for
OpenCVinterface OpenCVUtils {
fun Bitmap.toMat(): Mat {
val mat = Mat()
Utils.bitmapToMat(this, mat)
return mat
}
fun Mat.toBitmap(): Bitmap {
val bitmap = Bitmap.createBitmap(width(), height(),
Bitmap.Config.ARGB_8888)
Utils.matToBitmap(this, bitmap)
return bitmap
}
}
35. LINE Creators Studio ❤ Kotlin
Creators Studio Extensions for
OpenCV
val bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888)
val mat = bitmap.toMat()
val newBitmap = mat.toBitmap()