我有点健忘 已经做了很多次,从上次我做的时候找不到代码 如何让它调整多张图片的大小
我喜欢这个
Guid imageName;
imageName = Guid.NewGuid();
string storePath = Server.MapPath("~") + "/MultipleUpload";
if (!Directory.Exists(storePath))
Directory.CreateDirectory(storePath);
hif.PostedFile.SaveAs(storePath + "/" + Path.GetFileName(hif.PostedFile.FileName));
string tempPath = "Gallery";
string imgPath = "Galleryt";
string savePath = Path.Combine(Request.PhysicalApplicationPath, tempPath);
string TempImagesPath = Path.Combine(savePath, imageName + hif.PostedFile.FileName);
string imgSavePath = Path.Combine(Request.PhysicalApplicationPath, imgPath);
string ProductImageNormal = Path.Combine(imgSavePath, "t__" + imageName + hif.PostedFile.FileName);
string extension = Path.GetExtension(hif.PostedFile.FileName);
switch (extension.ToLower())
{
case ".png": goto case "Upload";
case ".gif": goto case "Upload";
case ".jpg": goto case "Upload";
case "Upload": hif.PostedFile.SaveAs(TempImagesPath);
ImageTools.GenerateThumbnail(TempImagesPath, ProductImageNormal, 250, 350, true, "heigh");
Label1.Text = "";
break;
}
答案 0 :(得分:0)
我发现了自己 但无论如何,谢谢你看
但现在我有另一个问题 我不会将原始文件保留在页面上,当它完成调整大小时应再次删除它 如果我只是在
代码中删除它File.Delete(Server.MapPath("~/Gallery/" + imageName + hif.PostedFile.FileName));
所以它说它无法删除该文件,因为它正被另一个进程使用。
string storePath = Server.MapPath("~") + "/MultipleUpload";
if (!Directory.Exists(storePath))
Directory.CreateDirectory(storePath);
string tempPath = "Galleryt";
string imgPath = "Gallery";
string savePath = Path.Combine(Request.PhysicalApplicationPath, tempPath);
string imgSavePath = Path.Combine(Request.PhysicalApplicationPath, imgPath);
string imgSavePath2 = Path.Combine(Request.PhysicalApplicationPath, imgPath);
string ProductImageNormal = Path.Combine(imgSavePath, imageName + hif.PostedFile.FileName);
string ProductImagetemp = Path.Combine(savePath, "t__" + imageName + hif.PostedFile.FileName);
string ProductImagetemp2 = Path.Combine(imgSavePath2, "b__" + imageName + hif.PostedFile.FileName);
string extension = Path.GetExtension(hif.PostedFile.FileName);
switch (extension.ToLower())
{
case ".png": goto case "Upload";
case ".gif": goto case "Upload";
case ".jpg": goto case "Upload";
case "Upload": hif.PostedFile.SaveAs(ProductImageNormal);
ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp, 600, 600, true, "heigh");
ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp2, 250, 350, true, "heigh");
Label1.Text = "";
break;
default:
Label1.Text = "Status: Denne filtype er ikke tilladt";
return;
}