개발 창고/Android

[Kotlin] drawable resource 불러오기

로이제로 2023. 2. 21. 22:00
반응형
val image: Bitmap = BitmapFactory.decodeResource(resources, R.drawable.bg_metal)

만약 아래와 같이 app > src > res > drawable에 있는 이미지 파일(bg_metal.png)을 불러와 사용하는 경우

 

Java source의 경우 아래와 같이 Bitmap으로 불러와 사용 가능하며

Bitmap image = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_metal);

Kotlin의 경우 아래와 같이 호출하여 사용 가능합니다.

val image: Bitmap = BitmapFactory.decodeResource(resources, R.drawable.bg_metal)

 

반응형

'개발 창고 > Android' 카테고리의 다른 글

mac android 폰 미러링 - scrcpy  (0) 2023.04.13
[Android] 다국어 설정  (0) 2023.04.08
[Kotlin] LPAD / RPAD  (0) 2023.02.12
[Kotlin] 화면 꺼지지 않게 하기  (0) 2023.02.12
[Kotlin] RGB to COLOR  (0) 2023.02.11