Solved:. The answer was to upgrade all nuget packages and configure a newer version of Android. Images are now loading as expected. I am not happy with this, since I used exactly the code that Xamarin provided and intended for newer versions, did not approve of some of the elements that the code refers to. The original version was Xamarin.Forms v23 and I upgraded to V25
I have a new Xamarin forms project with a simple view in which I am trying to display an image. I tried several ways to get the image to display, and I was not lucky at all.
I am using <image> and I also tried the FFImageLoader control.
<StackLayout Orientation="Vertical"> <ff:CachedImage Source="https://static.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg" WidthRequest="100" HeightRequest="100" /> <Button x:Name="btn" Text="Image" Clicked="Button_Clicked" /> <Frame OutlineColor="Red"> <Image x:Name="StupidImage" Source="{Binding Thumbnail}" Aspect="Fill" HeightRequest="100" WidthRequest="100" /> </Frame> </StackLayout>
This is the current view. I also set the source directly to a value with no result.
I can get the stream for the image. I can read all bytes from the stream. I built a debug visualizer to display bytes as an image. Getting the image from the source is not a problem. Obtaining image controls to display an image is a problem.
I tried binding to the view model. When this failed, I tried to directly set the source
StupidImage.Source = ImageSource.FromStream(() => result.Stream);
I also made a copy of the bytes and tried
StupidImage.Source = ImageSource.FromStream(() => new MemoryStream(imageBytes));
I tried ImageSource.FromFile() and .FromUri . I tried to add an image to the project as a resource. Each attempt was the same, the resource was read, and bytes were available, but the image control simply does not display it.
I thought this was a size issue, so I set the size of the control. Nothing. I thought this was a resolution problem, so I used a smaller image. I tried several different images of various quality.
Then I gave up image control, and I got the FFImageLoading nuget package and gave it the direct image URL. Same example as the FFImageLoading examples. No image yet.
I tried the emulator and I tried 2 different physical devices. The same result.
I also tried to set the image on the button using btn.Image = "whatever.jpg" with the same result.
This is the result every time. I'm lost. How do I display images?
EDIT: I got this to work, but only on an emulator
<Image x:Name="StupidImage" Source="https://static.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg" />
and the same for
StupidImage.Source = ImageSource.FromUri(new Uri("https://static.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg"));
EDIT 2 - Clarification
My goal is to allow the user to select a photo from the device and then display its preview.
