lundi 9 novembre 2015

save image to http server

Get an image from a http server. Resize the image to a thumnail and save back to the same folder as a different name "thumb" + imgName. This all works apart from saving to the server again. I tried saving to local and it works so the server is the problem

    Image fullsizeImage = Image.FromStream(new MemoryStream(new WebClient().DownloadData(ResolveUrl(ConfigurationManager.AppSettings["ImagesFolder"] + exportedFileName))));
    Image thumbImage = fullsizeImage.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
 thumbImage.Save(Server.MapPath(ResolveUrl(ConfigurationManager.AppSettings["ImagesFolder"] + "thumb_" + exportedFileName)));

This wont allow me to thumbImage.Save() back to the external server http it flags as 'http:/localhost:61318/Uploads/thumb_6086Jellyfish.jpg' is not a valid virtual path.

So I need to pass it to a memory stream first?? I tried

string destinationFileName = ResolveUrl(ConfigurationManager.AppSettings["ImagesFolder"] + "thumb_" + exportedFileName);
 System.IO.FileStream fs = System.IO.File.Open(destinationFileName, FileMode.Create);
thumbImage.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
 fs.Close();
 //BUT THIS FLAGGED AS - uri formats are not supported

So Do I need to creat the memory first? then save the image to that path...any ideas? thanks

Aucun commentaire:

Enregistrer un commentaire