我试图在后面的代码中加载一个图像。我可以使用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/ image /alpha.jpg.jpg”的图像。构建内容是MauiImage。
但是这是mainpage.xaml.cs文件中的代码。
ImageView1.Source = "CWON22.Resources.Images.beta.jpg";图像控制,ImageView1是空白。
发布于 2022-08-26 19:56:10
试试这个:
ImageView1.Source = new BitmapImage(
new Uri(@CWON22.Resources.Images.beta.jpg, UriKind.RelativeOrAbsolute)
);发布于 2022-08-29 02:53:42
如果要加载嵌入式映像,请将Build Action设置为Embedded resource
并参考以下代码:
ImageView1.Source = ImageSource.FromResource("CWON22.Resources.Images.test.png");有关更多信息,请查看:加载嵌入图像。
https://stackoverflow.com/questions/73505768
复制相似问题