c# - Xamarin 图像控件未设置图像源
问题描述
当我尝试从 TcpClient 每 20 毫秒将图像设置为内存流时,图像源未在 Xamarin 的图像控件中设置,我想知道在图像控件中设置 ImageSource 所需的时间是否存在某种限制调试器的输出,: https ://pastebin.com/8FgN5Rai
private Task<ImageSource> GetImageAsync(System.IO.Stream stream)
{
TaskCompletionSource<ImageSource> tcs = new TaskCompletionSource<ImageSource>();
tcs.TrySetResult(ImageSource.FromStream(() => (MemoryStream)formatter.Deserialize(client.GetStream())));
return tcs.Task;
}
private async void ReceiveImage()
{
while (client.Connected)
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(new Action(async () =>
{
imageControl.Source = await GetImageAsync(client.GetStream());
}));
}
}
好的,我必须设置图像,但它说不是有效的图像对象
好的,我尝试了更新的版本,但流中的图像无效?
图像加载:图像加载失败:System.Runtime.Serialization.SerializationException:输入流不是有效的二进制格式。起始内容(以字节为单位)为:10-10-FF-10-10-10-FF-10-10-10-FF-10-10-10-FF-10-10
解决方案
推荐阅读
- android - GCP API com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
- javascript - 这个解决方案可以替代 O(n^2) 或 O(n*m) 算法还是仍然是 O(n^2) 或 O(n*m) 算法?
- php - Laravel 8 Livewire 搜索过滤器不适用于第一个 where 子句
- visual-studio - Visual Studio 2010 中有用的多行字符串监视窗口在较新版本中的位置在哪里?
- html - 离子标签按钮在选择时不会改变颜色
- postgresql - Postgres 获取足够的视图信息来重现它
- python - 为数据点查找集群的简单方法是什么?
- codesign - 公证和签名后无法运行应用程序
- azure-application-insights - 应用程序洞察警报与可配置的电子邮件收件人和电子邮件正文的通知?
- arrays - 在 C 上处理 CSV 存档和结构数组时出现问题