I query data including images from a webservice.
In Xamarin, the data are stored in a list with 1-n objects.
The image-data in the list are stored as string (Base64-Coded).
Now I try to show the result (more than one field) in a custom cell-definition.
Until now, I was able to show more than one label filled with the data from the list.
But I have problems to show the image-data from the list and convert the data “on-the-fly”.
Code that works for a single image/datafield (without set binding to list, where the image data are stored in eq.bPFA_Grid_Foto)
// Overtake string-data from object in variable
string cFotoBase64 = eq.bPFA_Grid_Foto; // Overtake string-data from object in variable
// Convert in Byte-Array with encoding
Byte[] ImageFotoBase64 = System.Convert.FromBase64String(cFotoBase64);
// Create Image and set stream from converted Byte-Array as source
FotoAnzeige = new Image { Source = ImageSource.FromStream(() => new MemoryStream(ImageFotoBase64)), WidthRequest = 200, HeightRequest = 200, BackgroundColor = Color.Aqua, };
How to put this all together (set list as datasource and convert + stream the images)?
For the labels the following code works:
var AdressLabel = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand
};
AdressLabel.SetBinding(Label.TextProperty, "cAdresse");
Where cAdresse is a field in the object in the list.
To display the image from List, I have tried:
var image = new Image
{
HorizontalOptions = LayoutOptions.Start
};
image.SetBinding(Image.SourceProperty, new Binding(ImageSource.FromStream(() => new MemoryStream(System.Convert.FromBase64String(“bAnbieterFoto”));
Where bAnbieterFoto ”cAdresse is a text-field in the object in the list that contains the Base64-coded image-data as string.
With this code, I have an error-message “Cannot convert from xamarin.forms.Imagesource to string”.
Question:
- What do I have to change in my code, that it works?
Thanks for any help