1

still new in Xamarin forms I am trying to add an Image.

I opened a new PCL project have a login form and a main page.

I want to add to the main page the 2 images however one the image cause the project to crash and called an unhandeled exception.

the is in the project. and add it also to the drawable libery of the Android project.

hope to get help thanks.

attaching my XAML the secound image called tmpImage is doing the issue:

<?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>
4
  • What's the dimensions (width and height in pixels) of your images? Commented Jul 12, 2017 at 19:43
  • What is the exact exception? Commented Jul 12, 2017 at 19:51
  • Is Build Action set to AndroidResource? Commented Jul 12, 2017 at 21:51
  • Where does is Relative Layout used? I see you using RelativeLayout Height and Width Constraints, but I don't see a <RealtiveLayout> anywhere in your markup Commented Jul 13, 2017 at 19:45

1 Answer 1

1

Check your image name once logo_ComplexInstructions.jpg is it correct or not

And

I thought .jpg images don't support Xamarin.Forms(I don't know exatactly)

Follow below links

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

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like they use .jpg in the developer docs, but I haven't tested myself: developer.xamarin.com/guides/xamarin-forms/user-interface/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.