Android Application

Kotlin 이미지(Image) : 비트맵 - 이미지 불러오기

작성자 임베디드코리아 작성일23-10-17 00:50 조회1,460회 댓글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.sundown)
            var picX = (this.width - picture.width) /2f
            var picY = (this.height - picture.height) / 2f
            canvas.drawBitmap(picture, picX, picY, null)
            picture.recycle()
        }
    }
}