首页 > 解决方案 > 为什么此图像未加载到我的 Xamarin 移动应用程序中

问题描述

所以这是我必须生成图像及其大小的代码。每当我运行此代码时,图像都不会出现。icon.png 位于每个子文件夹中的我的 Android 资源文件中,它是预安装的图像之一,因此它应该能够找到图像并显示它。我试图将完整路径放入 File = "" 部分,但这也不起作用我怎样才能显示此图像?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration;

namespace PlatformBitmaps
{
   


public partial class MainPage : ContentPage
{
    public MainPage()
    {
        Image image = new Image
        {
            Source = new FileImageSource { File = "icon.png" }
        };
        

        Label label = new Label
        {
            FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.CenterAndExpand
        };

        image.SizeChanged += (sender, args) =>
        {
            label.Text = string.Format("Rendered size = {0} x {1}",
                image.Width, image.Height);
        };

        Content = new StackLayout
        {
            Children =
            {
                image, label
            }
        };
    }
}

}

标签: c#xamarinxamarin.formsxamarin.android

解决方案


推荐阅读