繁体   English   中英

.NET 毛伊岛加载图片

[英].NET Maui Load Image

我正在尝试在后面的代码中加载图像。 我可以使用 xaml 成功地将图像加载到图像控件中,但在我的 xaml.cs 文件中没有出现任何内容。

这是我的 xaml:

   <Image Grid.Row="1" Grid.RowSpan="1" Grid.Column="0"  x:Name="ImageView1"  HorizontalOptions="Start" VerticalOptions="CenterAndExpand" Source="alpha.jpg" />

加载来自“Resources/Images/alpha.jpg”的图像。 构建内容是 MauiImage。

但这里是mainpage.xaml.cs文件中的代码。

   ImageView1.Source = "CWON22.Resources.Images.beta.jpg";

图像控件 ImageView1 为空白。

尝试这个:

ImageView1.Source = new BitmapImage(new Uri(@CWON22.Resources.Images.beta.jpg, UriKind.RelativeOrAbsolute));

尝试:

ImageView1.Source = new ImageSource.FromResource("beta.jpg");

// OR
ImageView1.Source = new ImageSource.FromResource("Resources/Images/beta.jpg");

如果要加载嵌入的图像,请将Build Action设置为Embedded resource

并参考以下代码:

ImageView1.Source =   ImageSource.FromResource("CWON22.Resources.Images.test.png");

有关更多信息,请查看: 加载嵌入式图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM