C# 如何调整图像大小
我有点健忘 已经做了很多次了,但是找不到上次做的代码 如何调整多张图片的大小 我确实喜欢这个C# 如何调整图像大小,c#,image,resize,C#,Image,Resize,我有点健忘 已经做了很多次了,但是找不到上次做的代码 如何调整多张图片的大小 我确实喜欢这个 Guid imageName; imageName = Guid.NewGuid(); string storePath = Server.MapPath("~") + "/MultipleUpload"; if (!Directory.Exists(storePath)) Directory.CreateDirectory(storePath); hif.PostedFile.SaveAs(s
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;
}
我发现自己
不过还是谢谢你的关注
但现在我有另一个问题
我不会将原始文件保留在页面上,它应该在完成调整大小后再次删除
如果我在代码中用
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;
}
“e”标签的用途是什么?我已经试过设置它了。我认为这有点像ImageTools.GenerateThumbnail(TempImagesPath,TempImagesPath,250350,真的,“嗨”);但是Andrew所说的Didnt Work将有助于清理代码,因为大小调整问题与上载过程无关。