【发布时间】:2017-06-06 08:15:37
【问题描述】:
我参考这个网站https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images问这个问题
我在网站上尝试了 xaml 代码并且它可以工作,但是在我创建了一个新的 xamarin PCL 项目并测试了 c# 代码之后。无法显示图片。
我做了什么: 从 AboutPage.xaml 中删除所有内容,直到它看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="EmbbedImages.Views.AboutPage"
xmlns:vm="clr-namespace:EmbbedImages.ViewModels;"
Title="{Binding Title}">
<ContentPage.BindingContext>
<vm:AboutViewModel />
</ContentPage.BindingContext>
</ContentPage>
然后对于 AboutPage.xaml.cs,我对其进行了修改,使其如下所示:
using Xamarin.Forms;
namespace EmbbedImages.Views
{
public partial class AboutPage : ContentPage
{
public AboutPage()
{
InitializeComponent();
var beachImage = new Image { Aspect = Aspect.AspectFit };
beachImage.Source = ImageSource.FromFile("butterfly.jfif");
}
}
}
我已确保将 butterfly.jfif 图像添加到我的 android 可绘制文件夹中,但是没有显示任何图像。由于我是 xamarin 和 Android 以及 c# 的新手,我们将不胜感激。
【问题讨论】:
-
如果您将图像的扩展名更改为
.jpg是否有效?查看this 资源,似乎不支持.jfif图像格式。 -
您的
.jfif文件实际上是 jpeg 编码文件吗?仅供参考:文件扩展名无关紧要,您可以将 jpeg 扩展名更改为.fubar,Android 将加载并显示它,因为解码器使用文件的内容,而不是扩展名来确定它是什么类型的图像,但它必须是受支持的格式。