0Pricing
Jetpack Compose Academy · 课时

Image Composable

在屏幕上绘制可绘制资源。

Image Composable 是 CoddyKit 上的免费 Jetpack Compose Academy 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Jetpack Compose Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Jetpack Compose Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Pictures, the Compose Way

Every app shows pictures, and in Compose you draw them with the Image composable. It is the declarative replacement for the old ImageView. 🖼️

You Need a Painter

Image does not take a raw resource id. It takes a painter, a small object that knows how to draw your picture onto the screen.

painterResource Loads Drawables

To turn a drawable in res into a painter, you call painterResource with its resource id. This reads your PNG or vector asset.

val logo = painterResource(id = R.drawable.logo)

Your First Image

Pass that painter to Image and it appears on screen. This single line draws your drawable wherever the composable sits.

Image(painter = painterResource(R.drawable.logo), contentDescription = null)

contentDescription Is Required

Image always asks for a contentDescription. Screen readers speak it aloud, so describe the picture in a few clear words.

Image(painter = logo, contentDescription = "Company logo")

Decorative? Pass null

If a picture is purely decorative and adds no meaning, set contentDescription to null so TalkBack skips it instead of reading noise.

Vectors Scale Cleanly

Compose loves vector drawables. A vector stays razor sharp at any size because it is math, not fixed pixels, so it never looks blurry.

Size It with a Modifier

An Image draws at the bitmap size by default. Add a Modifier.size to make it exactly the dimensions your layout needs.

Image(painter = logo, contentDescription = null, modifier = Modifier.size(96.dp))

Bitmaps from the Network

painterResource only handles local assets. For remote URLs you reach for a loader library, the most popular being Coil with rememberAsyncImagePainter.

Tinting an Image

You can recolor a simple image with a colorFilter. This is great for monochrome icons you want to match your theme color.

Image(painter = logo, contentDescription = null,
    colorFilter = ColorFilter.tint(Color.Blue))

Image vs Icon

Use Image for photos and rich artwork. For small, theme-tinted symbols, the lighter Icon composable is usually the better choice.

Quick Check

Which argument does the Image composable always require alongside the painter?

Recap: Drawing Images

You learned that Image draws a painter from painterResource, always needs a contentDescription, and sizes with a modifier. Next up: Material icons! ✨

常见问题解答

「Image Composable」课时是免费的吗?

是的 — 「Image Composable」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Jetpack Compose Academy 课程的其余内容,请升级到 CoddyKit PRO。 Jetpack Compose Academy 课程共包含 4 节课。

「Image Composable」这节课中我会学到什么?

在屏幕上绘制可绘制资源。 你通过在浏览器中直接运行的动手代码来练习 Jetpack Compose Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Jetpack Compose Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Jetpack Compose Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「Image Composable」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Jetpack Compose Academy 课中编写并运行代码吗?

能。每节 Jetpack Compose Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Image Composable
  2. 使用 Icon 显示 Material 图标
  3. ContentScale 与裁剪
  4. 裁剪并设置图像形状
← 返回 Jetpack Compose Academy