我將crypto.png影像放入 Android 專案中 Resources 下的 drawable 檔案夾中。
在我右鍵單擊影像 -> Build Action -> Embedded Resource 后。
在MainPage.xaml主專案中,我嘗試像這樣加載影像:
<Image x:Name="HeadImage"
WidthRequest="100"
HeightRequest="100"
MinimumHeightRequest="100"
MinimumWidthRequest="100"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
Aspect="AspectFit"
Source="crypto.png"/>
但影像未加載。
我在 c# 代碼中嘗試了第二種方法:
var HeadImage = new Image { Aspect = Aspect.AspectFit };
HeadImage.Source = ImageSource.FromFile("crypto.png");
而且這個方法又沒用了..

uj5u.com熱心網友回復:
您需要讓您的影像在drawable檔案夾中Android Resource而不是Embedded Resource,并且要使用它,您需要:
HeadImage.Source = "crypto.png";
此外,在設定影像之前,洗掉MinimumWidthRequest and MinimumHeightRequest. 僅當您確定影像具有此最小尺寸時,這才是安全的。否則,您的影像將不會出現。
要了解有關 Xamarin 中影像的更多資訊,請參閱此處。
并了解設定方式之間的差異,ImageSource請參閱此處。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/384134.html
上一篇:在Excel中將數字轉換為非數字
