Good morning, I'm trying to open, resize, and save an image again through an ASP.NET application, but I'm getting an error when the image will be saved. Here is the code that is giving error:
public void MudarResolução(string nome)
{
string fileName = nome;
string imagem = string.Format("C:\Desenvolvimento\Sistema\Captures\{0}.png", fileName);
try
{
Image myImg = Image.FromFile(imagem);
myImg = resizeImage(myImg, new Size(85, 104));
myImg.Save(string.Format("C:\Desenvolvimento\Sistema\Captures\{0}.png", fileName), ImageFormat.Png);
}
catch(Exception e)
{
throw new Exception();
}
}
The error you are giving in Exception is "Generic Error GDI +" and in the "myImg.Save ..." line, but I can not understand what it is. Thanks in advance to anyone who can help.
Another method that is working:
public ActionResult Capture()
{
if (Request.InputStream.Length > 0)
{
using (StreamReader reader = new StreamReader(Request.InputStream))
{
string hexString = Server.UrlEncode(reader.ReadToEnd());
string imageName = Convert.ToString(Session["Nome_Foto"]);
string imagePath = string.Format("~/Captures/{0}.png", imageName);
System.IO.File.WriteAllBytes(Server.MapPath(imagePath), ConvertHexToBytes(hexString));
//apenas mostra a imagem capturada na tela a direita
Session["CapturedImage"] = VirtualPathUtility.ToAbsolute(imagePath);
}
}
MudarResolução(imageName);
return View();
}
public static Image resizeImage(Image imgToResize, Size size)
{
return (Image)(new Bitmap(imgToResize, size));
}
Note: The "Capture ()" method saves an image in size 320x240 in the "Captures" directory, what I want to do is to open this saved image, resize it (85x104) and save the new image in the same or directory.