Android Application

Kotlin 이미지(Image) : 컬러매트릭스(ColorMatrix)

작성자 임베디드코리아 작성일23-10-20 23:53 조회1,395회 댓글0건

첨부파일

Kotlin 이미지(Image) : 컬러매트릭스(ColorMatrix)
------------------------------------------------------------------------------------
    MainActivity.kt
------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)

        setContentView(MyGraphicView(this))
    }

    private class MyGraphicView(context: Context) : View(context) {

        override fun onDraw(canvas: Canvas) {
            super.onDraw(canvas)

            var picture = BitmapFactory.decodeResource(resources,  R.drawable.sup)

            var picX = (this.width - picture.width) / 2f
            var picY = (this.height - picture.height) / 2f

            var paint = Paint()

            canvas.translate(5f, -500f)
            canvas.drawBitmap(picture, picX, picY, paint)

            var array = floatArrayOf( 2f, 0f, 0f, 0f, -25f,
                0f, 2f, 0f, 0f, -25f,
                0f, 0f, 2f, 0f, -25f,
                0f, 0f, 0f, 1f,  0f )
            var cm = ColorMatrix(array)
            paint.colorFilter = ColorMatrixColorFilter(cm)

            canvas.translate(5f, 1000f)
            canvas.drawBitmap(picture, picX, picY, paint)
            picture.recycle()
        }
    }

}