从FTP服务器读取图像(TIF图像)

时间:2011-12-13 08:25:52

标签: c# sharepoint-2010 ftp tiff

我想从FTP服务器读取图像(TIF图像),然后查看它 我曾经从FTP服务器上读过这段代码:

//CREATE AN FTP REQUEST WITH THE DOMAIN AND CREDENTIALS
                    System.Net.FtpWebRequest tmpReq =     (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(filePath);
                    tmpReq.Credentials = new System.Net.NetworkCredential(userName, password);
                //GET THE FTP RESPONSE
                using (System.Net.WebResponse tmpRes = tmpReq.GetResponse())
                {
                    //GET THE STREAM TO READ THE RESPONSE FROM
                    using (System.IO.Stream tmpStream = tmpRes.GetResponseStream())
                    {
                        //CREATE A TXT READER (COULD BE BINARY OR ANY OTHER TYPE YOU NEED)
                        using (System.IO.TextReader tmpReader = new System.IO.StreamReader(tmpStream))
                        {

                            //read and view image


                        }
                    }
                }
            }

我需要你的帮助如何将TIF图像转换为Jepg或其他类型,以及如何使用我的代码从FTP读取TIF

感谢

2 个答案:

答案 0 :(得分:3)

您可以使用Image类来执行转换。还要确保处置一次性资源,例如网络流:

class Program
{
    static void Main()
    {
        var filePath = "ftp://example.com/foo.tif";
        var request = WebRequest.Create(filePath);
        request.Credentials = new NetworkCredential("user", "pass");
        using (var response = request.GetResponse())
        using (var stream = response.GetResponseStream())
        using (var img = Image.FromStream(stream))
        {
            img.Save("foo.jpg", ImageFormat.Jpeg);
        }
    }
}

答案 1 :(得分:0)

有关TIFF-JPEG转换的信息,请参阅this

你是在正确的课程 - 阅读我发布的主题并使用适当的对象保存你的数据

编辑:

来自MSDN的FtpClient还有一些reading