在 Kotlin Compose 桌面中加载图像时出现问题
Problems Loading image in Kotlin Compose desktop
我在 kotlin compose for desktop 中加载图像时遇到问题
它给出了以下错误:
image.png resource not found
我在项目的src文件夹中有文件
我不确定问题出在代码还是我导入图像的方式,或者即使问题出在 kotlin compose for desktop 的实验性质上
val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
Image(bitmap = useResource("image.png") { loadImageBitmap(it) },
"image",
imageModifier,
contentScale = ContentScale.Fit)
将图像文件保存在 resources 文件夹中,然后像这样使用它
val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
Image(painter = painterResource("image.png"),
contentDescription = "image",
imageModifier,
contentScale = ContentScale.Fit
)
painterResource
支持光栅(BMP、GIF、HEIF、ICO、JPEG、PNG、WBMP、WebP)和矢量格式(SVG、XML 矢量可绘制)。
有关此访问的更多信息,请访问此处 https://github.com/JetBrains/compose-jb/tree/master/tutorials/Image_And_Icons_Manipulations
我在 kotlin compose for desktop 中加载图像时遇到问题
它给出了以下错误:
image.png resource not found
我在项目的src文件夹中有文件
我不确定问题出在代码还是我导入图像的方式,或者即使问题出在 kotlin compose for desktop 的实验性质上
val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
Image(bitmap = useResource("image.png") { loadImageBitmap(it) },
"image",
imageModifier,
contentScale = ContentScale.Fit)
将图像文件保存在 resources 文件夹中,然后像这样使用它
val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
Image(painter = painterResource("image.png"),
contentDescription = "image",
imageModifier,
contentScale = ContentScale.Fit
)
painterResource
支持光栅(BMP、GIF、HEIF、ICO、JPEG、PNG、WBMP、WebP)和矢量格式(SVG、XML 矢量可绘制)。
有关此访问的更多信息,请访问此处 https://github.com/JetBrains/compose-jb/tree/master/tutorials/Image_And_Icons_Manipulations