CodeGo.net>如何从FTP设置图像的图像源

时间:2018-07-22 07:38:37

标签: xamarin.forms xamarin.android ftp-client

所以我有这段代码从我的FTP服务器获取图像,然后我要从ftp服务器设置其源。我从这行cannot convert 'System.IO.Stream' to 'System.Func<System.IO.Stream>'那里得到的imgs.Source = ImageSource.FromStream(img);

我正在Android btw上使用xamarin.Forms。

private void loadImage(string source)
        {
            try
            {
                string ftpfullpath = source;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.DownloadFile;

                using (var request = ftp.GetResponse())
                {
                    using (var img = request.GetResponseStream())
                    {
                        imgs.Source = ImageSource.FromStream(img);
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

0 个答案:

没有答案