繁体   English   中英

图像未显示 Xamarin.Forms

[英]Image not displaying Xamarin.Forms

我正在开发一个 Xamarin 应用程序,它是我一直在从事的另一个项目 API 的一部分

因此 API 将个人资料图片作为字节 [] 发送到 Xamarin 应用程序,但 Xamarin 应用程序没有显示它。

到目前为止,我已经尝试了来自不同平台的许多选项,包括这里,但仍然无法正常工作

我尝试将图像转换为 base 64 字符串,然后将其转换回 byte[],然后再使用

imageProfilePic.Source = ImageSource.FromStream(() => new MemoryStream(base64Stream.ToArray()));

我尝试过的其他选项包括直接使用数组创建 memory stream object ,我什至尝试将图像作为基本 64 字符串返回并使用 new MemoryStream 将其转换为显示字节数组。

我开始认为 Xamarin 存在严重问题。

有没有办法我可以从 API 只返回图像 URL,我认为这将是更好的选择,

我使用 EF Core 和 MS SQL 将图像作为 byte[] 数组存储在数据库中

您能否将 Base64 字符串转换为字节数组,如下所示:

var byteArray = Convert.FromBase64String(base64Stream);

然后设置图像源;

imageProfilePic.Source = ImageSource.FromStream(()=> new MemoryStream(byteArray));

I actually found a way to display, I used the URL, Since I had access to the API, I decided to tweak the API so that instead of storing the images to the database, I stored them in the file server and stored their URL in数据库,我将返回 URL 和 API 并使用它来访问格式中的图片

本地主机:/图像/图片.jpg

由于我在本地托管 API,因此 localhost 将替换为 IP 地址

在 Android 应用程序中,它将是

图片.Source = ImageSource.FromUri(myUri);

它就像一个魅力

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM