What is wrong with the code below?
private MemoryStream resizedImage(string filePath)
{
MemoryStream ms = new MemoryStream();
int maxImgWidth = int.Parse(ConfigurationManager.AppSettings["maximgwidth"]);
Bitmap bm = (Bitmap)System.Drawing.Image.FromFile(filePath);
if (bm.Width > maxImgWidth)
{
int newWidth = maxImgWidth;
double auxCalculo = (double)newWidth / (double)bm.Width;
double newHeight = auxCalculo * bm.Height;
Bitmap Resized = new Bitmap(newWidth, (int)newHeight);
Graphics g = Graphics.FromImage(Resized);
g.DrawImage(bm, new Rectangle(0, 0, Resized.Width, Resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
g.Dispose();
Resized.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms;
}
private void enviaImagem(string codImovel, String caminhoArquivo, int contador)
{
string remoteFileName = codImovel.Trim() + "_" + (contador + 1).ToString() + ".jpg";
[b]MemoryStream ms = resizedImage(caminhoArquivo);[/b]
fileLength = ms.Length;
ftpConn.Connect();
ftpConn.CloseStreamsAfterTransfer = true;
ftpConn.BytesTransferred += new BytesTransferredHandler(ftpConn_BytesTransferred);
ftpConn.ChangeWorkingDirectory(ConfigurationManager.AppSettings["FTPImageFolderVenda"]);
[b]ftpConn.UploadStream(ms, remoteFileName);[/b]
ftpConn.Close();
Application.DoEvents();
System.Threading.Thread.Sleep(40);
ResetaBarra(100);
updateStatusKbTrans("Imagem enviada com sucesso!");
}
I'm trying to resize the image before send it to server saving bandwidth and time but it never works. Always send 0 bytes.
The memory stream is filled, I check it out in debug and I could get the stream length to feedbak the user but the bytes are not sent.
Thanks in advance.
John