微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么此图像无法加载到我的Xamarin Mobile App中

如何解决为什么此图像无法加载到我的Xamarin Mobile App中

所以这是生成图像及其大小的代码。每当我运行此代码时,图像都不会显示。 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
            }
        };
    }
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。