Reputation: 311
i wanna read an image (TIF image) from FTP Server and then view it i used to read from FTP server this code:
//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
}
}
}
}
i need your help how to convert TIF image to Jepg or other type and also how to read TIF from FTP using my code
thanks
Upvotes: 0
Views: 3191
Reputation: 25595
See this regarding TIFF-JPEG conversion.
You're on the right course - read the thread I posted and save your data using the proper Objects
EDIT:
Some further reading as for the FtpClient from MSDN
Upvotes: 0
Reputation: 1039120
You could use the Image class to perform the conversion. Also make sure you dispose disposable resources such as network streams:
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);
}
}
}
Upvotes: 3