【问题标题】:Adding an Image to Xamarin forms将图像添加到 Xamarin 表单
【发布时间】:2017-07-12 19:22:18
【问题描述】:

在 Xamarin 表单中仍然是新的我正在尝试添加图像。

我打开了一个新的 PCL 项目,有一个登录表单和一个主页。

我想将 2 张图片添加到主页,但其中一张图片会导致项目崩溃并调用未处理的异常。

在项目中。并将其添加到 Android 项目的 drawable libery 中。

希望能得到帮助,谢谢。

将我的 XAML 附加到名为 tmpImage 的第二个图像正在解决问题:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:ComplexInstruction"
         x:Class="ComplexInstruction.MainPage">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="0,1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.1*"></RowDefinition>
    </Grid.RowDefinitions>


    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.1*"></ColumnDefinition>
        <ColumnDefinition Width="1*"></ColumnDefinition>
        <ColumnDefinition Width="0.1*"></ColumnDefinition>
        <ColumnDefinition Width="1*"></ColumnDefinition>
        <ColumnDefinition Width="0.1*"></ColumnDefinition>
    </Grid.ColumnDefinitions>


    <Image Aspect="Fill" Source="logo_ComplexInstructions.jpg" 
        RelativeLayout.WidthConstraint=
          "{ConstraintExpression Type=RelativeToParent, Property=Width}"
        RelativeLayout.HeightConstraint=
          "{ConstraintExpression Type=RelativeToParent, Property=Height}" Opacity="0.3" Grid.ColumnSpan="5" Grid.Row="0" Grid.RowSpan="2" />




       <Image x:Name="tmpImage" Aspect="Fill" Source="SHA_6620.jpg"
        RelativeLayout.WidthConstraint=
          "{ConstraintExpression Type=RelativeToParent, Property=Width}"
        RelativeLayout.HeightConstraint=
          "{ConstraintExpression Type=RelativeToParent, Property=Height}" 
 Grid.ColumnSpan="5" Grid.Row="3" Grid.RowSpan="8" />

</Grid>


</ContentPage>

【问题讨论】:

  • 图片的尺寸(宽度和高度,以像素为单位)是多少?
  • 确切的例外是什么?
  • 构建操作是否设置为AndroidResource
  • 相对布局在哪里使用?我看到您使用的是 RelativeLayout 高度和宽度约束,但我在您的标记中没有看到 &lt;RealtiveLayout&gt;

标签: c# xamarin xamarin.forms


【解决方案1】:

检查一下您的图片名称 logo_ComplexInstructions.jpg 是否正确

还有

我认为 .jpg 图像不支持 Xamarin.Forms(我不太清楚)

点击以下链接

https://developer.xamarin.com/api/type/System.Drawing.Imaging.ImageFormat/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-30
  • 2018-06-04
  • 2019-05-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多