c# - 为什么此图像未加载到我的 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# - 在实体框架中保存数据+关系数据的最佳/最简单方法
- javascript - 使用 jquery 的一页滚动网站
- jackson - 是否可以将请求 json 主体的 RFC3339 完整日期字段反序列化为 msf4j 应用程序中的某个 java 日期类?
- git - 创建 CI/CD heroku 、 git 和 jenkins
- amazon-web-services - dynamodb 是否适合成长型或可旋转的产品?
- python - 使用请求 HTML 找不到 css 类
- python - Django 对象 order_by 给我重复的用户
- rest - Golang REST API 项目结构
- javascript - 在某些特定网站上更改 chrome 扩展程序的图标
- reactjs - 如何使用物化和 scss 防止 @media 查询错误