Hi all, I've been working on an Xamarin Forms app which displays a user Id photo that is grabbed from a Restful service, using a post method with two parameters (eventId, linkid). I have set up a method that connects to the service and grabs the httpresponse message and then converts it into a byte array. This byte array is then converted into a memory stream and placed as the image source. However I am not getting anything showing up, even though I am getting a byte array. Here is my code:-
public Byte[] GrabPhoto(ScanResult[] result) {
//post method
string url = @"https://xxxxxx/xxxxx/Photo";
var values = new Dictionary<string, string>();
values.Add ("Event", eventName);
string link = result [0].LinkId.ToString ();
values.Add ("LinkId", link);
var content = new FormUrlEncodedContent(values);
var client = new HttpClient();
var httpResponse = client.PostAsync (url, content);
httpResponse.Wait();
Byte[] results = httpResponse.Result.Content.ReadAsByteArrayAsync ().Result;
return results;
}
// Profile image for ticket holder if applicable
var idImage = new Image { Aspect = Aspect.AspectFit };
idImage.Source = ImageSource.FromStream(() => new MemoryStream(GrabPhoto (test)));
idImage.HorizontalOptions = LayoutOptions.Center;
// Added to gridView
grid.Children.Add (idImage, 0, 0);
Any help would be greatly appeciated.