首页 > 解决方案 > 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

标签: c#xamarinxamarin.forms

解决方案


推荐阅读