唯客微博客

专注于计算机,嵌入式领域的技术

0%

Jetpack Compose组件-图片(Image)

Jetpack Compose组件-图片(Image)

图片(Image)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@Composable
@NonRestartableComposable
fun Image(
// 位图对象,可以显示 JPG,PNG 等格式的图标
bitmap: ImageBitmap,
// 无障碍功能, 图片描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 对齐方式
alignment: Alignment = Alignment.Center,
// 图片缩放方式
contentScale: ContentScale = ContentScale.Fit,
// 图片透明度
alpha: Float = DefaultAlpha,
// 颜色滤镜
colorFilter: ColorFilter? = null,
// 缩放时采样算法
filterQuality: FilterQuality = DefaultFilterQuality
): Unit

@Composable
fun Image(
// 画笔,可以使用画笔在 Canvas 上直接绘制图标,可以通过 res/ 下的图片资源来设置图标
painter: Painter,
// 无障碍功能, 图片描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 对齐方式
alignment: Alignment = Alignment.Center,
// 图片缩放方式
contentScale: ContentScale = ContentScale.Fit,
// 图片透明度
alpha: Float = DefaultAlpha,
// 颜色滤镜
colorFilter: ColorFilter? = null
): Unit

@Composable
@NonRestartableComposable
fun Image(
// 矢量图对象,可以显示 SVG 格式的图标
imageVector: ImageVector,
// 无障碍功能, 图片描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 对齐方式
alignment: Alignment = Alignment.Center,
// 图片缩放方式
contentScale: ContentScale = ContentScale.Fit,
// 图片透明度
alpha: Float = DefaultAlpha,
// 颜色滤镜
colorFilter: ColorFilter? = null
): Unit
1
2
3
4
5
6
Image(
painter = painterResource(id = R.drawable.newbanner4),
contentDescription = null,
contentScale = ContentScale.Inside,
colorFilter = ColorFilter.tint(Color.Red, blendMode = BlendMode.Color)
)

图片相关库

1
2
3
4
5
6
// Coil
implementation "io.coil-kt:coil-compose:2.2.2"
// Coil SVG
implementation "io.coil-kt:coil-svg:2.2.2"
// 图片放大缩小
implementation "com.github.skydoves:landscapist-coil:1.4.5"
-------------本文结束感谢您的阅读-------------

本文标题:Jetpack Compose组件-图片(Image)

文章作者:Vinx

发布时间:2023年01月12日 - 11:21

最后更新:2023年09月18日 - 11:41

原始链接:https://blog.vinkvin.com/post/61/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。