首先,我是Xamarin.Form的新手。我正在尽力从Google中获取最佳信息,但有些功能即使搜索了很多次也无法获得。
我正在创建一个Xamarin.Form应用程序。在该应用程序中,我将图像以base64字符串格式存储在sql server中,我的数据类型在sql server中是varchar(Max)。
我的问题是,如何将base64字符串转换为图像,并将图像绑定到列表视图。
Listview的代码:
我正在创建一个Xamarin.Form应用程序。在该应用程序中,我将图像以base64字符串格式存储在sql server中,我的数据类型在sql server中是varchar(Max)。
我的问题是,如何将base64字符串转换为图像,并将图像绑定到列表视图。
Listview的代码:
<ListView x:Name="listView" HasUnevenRows="true" SeparatorColor="Gray">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image Source="{Binding image}" Grid.Row="0"
Grid.RowSpan="3" Grid.Column="0"
HorizontalOptions="Center" HeightRequest="50"
VerticalOptions="Center">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnImageTapped" />
</Image.GestureRecognizers>
</Image>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
c#代码:
Public async Task loadDeveloperList()
{
try
{
List<employee> employeeDetail = new List<employee>();
HttpClient client = new HttpClient();
StringBuilder sb = new StringBuilder();
client.MaxResponseContentBufferSize = 256000;
var RestUrl = "http://example.com/Getemployee/";
var uri = new Uri(RestUrl);
actIndicator.IsVisible = true;
actIndicator.IsRunning = true;
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
List<employee> onjEmployee = JsonConvert.DeserializeObject<List<employee>>(content);
foreach (var item in onjEmployee)
{
employee emptemp = new employee()
{
empID = item.empID,
name = item.name,
city = item.city,
post = item.post,
salary = item.salary,
gender = item.gender,
image = item.image
};
string cFotoBase64 = emptemp.image;
byte[] ImageFotoBase64 = System.Convert.FromBase64String(cFotoBase64);
employeeDetail.Add(emptemp);
}
listView.ItemsSource = employeeDetail;
}
}
catch (Exception ex)
{
}
}
请有人给我提供一个想法和解决方案。