我在kotlin compose for desktop中加載圖片時遇到了問題
。它給出了以下錯誤:
image.png資源未找到
我在專案的 src 檔案夾中找到了該檔案
我不確定該檔案是否存在。
我不確定問題是出在代碼上還是我匯入圖片的方式上,甚至不確定問題是出在kotlin compose for desktop的實驗性質上
。val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
影像(bitmap = useResource("image.png") { loadImageBitmap(it) },
"image",
imageModifier,
contentScale = ContentScale.Fit)
uj5u.com熱心網友回復:
在resources檔案夾中保留你的圖片檔案,然后像這樣使用它
val imageModifier = Modifier
.height(240.dp)
.fillMaxWidth()
.剪輯(RoundedCornerShape(12.dp))
圖片(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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/328866.html
標籤:
