简体   繁体   English

如何调整图像大小

[英]how to resize image

I am a little forgetful have made it many times and can not find the code from the last time I made it how do I get it to resize more than one picture 我有点健忘,已经做过很多次了,但是我上次做的代码却找不到,我如何才能调整一张以上图片的大小

i do like this 我喜欢这样

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;
    }

I found out myself but thanks anyway for looking 我发现自己了,但还是感谢您的期待

but now I have another problem I will not keep the original file on the page it should be deleted again when it is finished resize If I just delete it right after in the code with 但现在我还有另一个问题,我不会将原始文件保留在页面上,当调整大小后,应该再次删除该文件。

File.Delete(Server.MapPath("~/Gallery/" + imageName + hif.PostedFile.FileName));

so it says that it can not delete the file because it is being used by another process. 因此它说它不能删除该文件,因为它正在被另一个进程使用。

                        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;

                        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM