What I'm doing here is I'm copying an image file from a terminal to my server using ftp. But when I check the picture in the server it suddenly becomes poor quality image.
I'm starting to think maybe it's because of my conversion from image to byte array. Can anyone help?
Here's my code..
Stream stream = FileUploadPic.FileContent;
System.Drawing.Image i = new Bitmap(stream);
var abort = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
var thumbnail = i.GetThumbnailImage(300, 300, abort, IntPtr.Zero);
byte[] bytes = imageToByteArray(thumbnail);
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(path);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
request.ContentLength = bytes.Length;
Stream req_Stream = request.GetRequestStream();
req_Stream.Write(bytes, 0, bytes.Length);
req_Stream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
This is the imageToByteArray
function:
public byte[] imageToByteArray(System.Drawing.Image imageIn) {
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}