ImageSource.FromStream()

Hi, I've been trying to get an image inside of a frame to display onscreen. Currently, I have a property in my ViewModel which is bound to from Xaml. When the image source is set in Xaml to a local file instead of this bindable source, the image displays just fine, but when the bindable property is used, there is no image, no error, or anything else suggesting a problem - just no image.

try{
_currentRecipe = await _recipeWebService.GetRecipe ();
_backRecipe = await _recipeWebService.GetRecipe ();
var currentPhotoStream = _currentRecipe.PhotoStream;
Debug.WriteLine(currentPhotoStream.Length);
currentPhotoStream.Position = 0;
FrameImage1 = ImageSource.FromStream(()=>currentPhotoStream);
}
catch(Exception exception) {
Debug.WriteLine (exception.ToString());
}

This is the current code I am using to change the bound property. I'm truly at a loss on how to fix this. The stream is of the correct length according to the web-server, and saving the stream into a file that I exported using Android Device Monitor resulted in a valid jpg file on my workstation tat opened normally.

Cheers

Posts

  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    Try this...
    Except FrameImage1 use Xamarin.Forms.Image control.
    In view model;
    public Xamarin.Forms.ImageSource PhotoStream { get; set; }
    Convert stream to image and assign to view model;
    PhotoStream = ImageSource.FromStream(()=>new MemoryStream(imageStream));
    Assign image like;
    Image1=PhotoStream;

Sign In or Register to comment.