Android Application

Kotlin 이미지(Image) : 비트맵 - 이미지의 기하학적 변환

작성자 임베디드코리아 작성일23-10-17 00:51 조회1,852회 댓글0건

첨부파일

Kotlin  이미지(Image)  : 비트맵 - 이미지의 기하학적 변환
회전, 확대/축소, 이동, 기울이기
------------------------------------------------------------------------------------
    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.gogung)

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

            canvas.rotate(45f, cenX, cenY)
            canvas.drawBitmap(picture, picX, picY, null)

            canvas.translate(-150f, 200f)
            canvas.drawBitmap(picture, picX, picY, null)

            canvas.scale(2f, 2f, cenX, cenY)
            canvas.drawBitmap(picture, picX, picY, null)

            canvas.skew(0.3f, 0.3f)
            canvas.drawBitmap(picture, picX, picY, null)

            picture.recycle()

        }
    }
}