我在这里做的是使用 ftp 将图像文件从终端复制到我的服务器。但是当我检查服务器中的图片时,它突然变得质量很差。
我开始认为这可能是因为我从图像转换为字节数组。任何人都可以帮忙吗?
这是我的代码..
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();
这是imageToByteArray
功能:
public byte[] imageToByteArray(System.Drawing.Image imageIn) {
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}