我问这个问题,参照本网站https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images有问题,显示仅使用C#
我想在网站上XAML代码但是它的工作原理,我创建了一个新的xamarin PCL项目和测试后的图像Xamarin形式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](https://developer.android.com/guide/topics/media/media-formats.html)资源,它不会显示支持'.jfif'图像格式。 –
你的'.jfif'文件实际上是一个jpeg编码文件吗?仅供参考:文件扩展名无关紧要,您可以将jpeg扩展名更改为'.fubar',Android将加载并显示它,因为解码器使用文件的内容,而不是扩展名来确定它是什么类型的图像,但它必须是支持的格式。 – SushiHangover