Android(kotlin) - JetPack Compose - Image

하동혁 ·2023년 8월 22일
0

Android Jetpack Compose

목록 보기
15/30
post-thumbnail
post-custom-banner

Image의 속성

예제

@Composable
fun Greeting() {
    Column {
        // painter
        Image(
            painter = painterResource(id = R.drawable.cat1),
            contentDescription = "image1",
        )

        // imageVector
        Image(
            imageVector = Icons.Filled.Search,
            contentDescription = "image2")

        // bitmap은 컴포저블 함수 내에서 진행할 수 없다. 
        // 추후에 학습할 예정
    }
}




Network Image

의존성 추가 (coil 라이브러리 사용)

  • build.gradle(app)
dependencies {
		
    // coil 의존성을 추가
    implementation 'io.coil-kt:coil:2.2.2' 
    implementation 'io.coil-kt:coil-compose:2.2.2' 
}
  • manifest
<uses-permission android:name="android.permission.INTERNET"/>
  • 방법 1
		// rememberImagePainter (Compose 한국어 문서의 추천, but Deprecated)
    val painter = rememberImagePainter(
        data = "https://img.freepik.com/free-photo/adorable-kitty-looking-like-it-want-to-hunt_23-2149167099.jpg?w=2000",
    )

    Image(
        painter = painter,
        contentDescription = "cat image",
    )
  • 방법 2
		// AsyncImage
    AsyncImage(
        model = "https://img.freepik.com/free-photo/adorable-kitty-looking-like-it-want-to-hunt_23-2149167099.jpg?w=2000",
        contentDescription = "cat image"
    )

post-custom-banner

0개의 댓글