0
나는 이미지 업로드를 위해 파일 업로드 컨트롤을 사용하고 있습니다.iam이 조건을 확인하는 경우 Image.Width> 250 || Image.Height> 400이면 이미지의 크기가 변경됩니다. 하지만 오류가 발생했습니다 "SaveAs 메서드가 루트 경로를 요구하도록 구성되어 있고 'ProductImages/roman_sandals.jpg'경로가 루팅되지 않습니다."업로드하는 동안 이미지 크기 조정
ProductImages는 이미지를 저장하는 폴더입니다. 당신이 경우
HostingEnvironment.ApplicationPhysicalPath
를 사용하여 이미지 경로와 결합 할 수
string strBigServerPath = AppHardcodeValue.productImgPath;
string strFileName = "";
if (prodImg.HasFile)
{
strFileName = prodImg.PostedFile.FileName;
string uniqueNum = Convert.ToString(System.Guid.NewGuid());
string shortFileName = System.IO.Path.GetFileName(strFileName);
string Extension = System.IO.Path.GetExtension(prodImg.FileName);
string newFileName = shortFileName;
prodImg.SaveAs(Server.MapPath(strBigServerPath + newFileName));
using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName))
{
if (Img.Width > 250 || Img.Height > 400)
{
Size MainSize = new Size(250, 400);
using (System.Drawing.Image ImgThnail =
new Bitmap(Img, MainSize.Width, MainSize.Height))
{
prodImg.SaveAs(strBigServerPath + newFileName);
}
}
Img.Dispose();
}
string ThumbnailPath = Server.MapPath(AppHardcodeValue.productThumbImgPath) + newFileName;
using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName))
{
Size ThumbNailSize = new Size(50, 50);
using (System.Drawing.Image ImgThnail =
new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
{
ImgThnail.Save(ThumbnailPath, Img.RawFormat);
ImgThnail.Dispose();
}
Img.Dispose();
}
}