嵌入式映像问题 Xamarin



所以我想要的是将我的应用程序徽标作为嵌入式png放入。看了很多教程,我觉得我已经真正复制了所有路径,但它仍然没有显示(显然我做错了什么,哈哈(。我目前拥有的是根本没有图像,即使我输入"local:ImageResource APRooved.Logoforappheader.png",我也会进入"APRooved",它仍然表明它是一个来源,一旦我把句号放进去,然后说"没有建议"。我的图像目前位于Android和iOS资源文件夹中,因为它是一个跨平台的应用程序,并且属性设置为EmbeddedResource。

有没有人有任何想法或可以让我朝着正确的方向前进?

下面是我的 XAML 代码段:

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:APRooved"
mc:Ignorable="d"
x:Class="APRooved.MainPage"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;    assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
BarBackgroundColor="#2B333F"
BarTextColor="#FFA600">
<ContentPage Title="Calculator" IconImageSource="Logoforappheader.png">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width ="1*" />
<ColumnDefinition Width ="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="3*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<BoxView Color="#2B333F"
CornerRadius="0"
Grid.Column="0"
Grid.ColumnSpan="5"
Grid.Row="0"
Grid.RowSpan="3"   
WidthRequest="700"
HeightRequest="200"
VerticalOptions="Center"
HorizontalOptions="Center" />

<Image Source="{local:ImageResource APRooved.Logoforappheader.png}" WidthRequest="300"     HeightRequest="100"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.Row="1"
Grid.RowSpan="1"></Image>

下面是我的图像资源扩展

using System;
using System.Reflection;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace APRooved
{
[ContentProperty(nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
{
return null;
}
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source,     typeof(ImageResourceExtension).GetTypeInfo().Assembly);
return imageSource;
}
}
}

我的图像目前位于Android和iOS资源文件夹中,因为它是 跨平台应用程序

如果图像是本地图像,则应将它们放在每个项目下的正确位置。

iOS- 自iOS9 以来管理和支持映像的首选方法是使用资产目录映像集,该映像集应包含支持应用程序的各种设备和缩放因子所需的映像的所有版本。

Android- 使用"构建操作:AndroidResource"将图像放在资源/可绘制目录中。 还可以提供映像的High- and low-DPI版本。

通用 Windows 平台 (UWP(- 使用"生成操作:内容"将映像放在应用程序的根目录中。

然后通过以下方式加载图像:

<Image Source="xxx.jpg" />

如果图像是嵌入图像,则应将它们放置在共享项目中并像您在问题中所做的那样加载它们。

最新更新