如何调整图像大小

发布于 2024-09-01 22:55:12 字数 1193 浏览 1 评论 0原文

我有点健忘 已经做了很多次了,找不到上次做的代码 如何让它调整多张

我喜欢的图片的大小

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ペ泪落弦音 2024-09-08 22:55:12

我发现我自己
但无论如何感谢您的关注

,但现在我有另一个问题
我不会在页面上保留原始文件,当它完成调整大小时应该再次删除它
如果我只是在代码中删除它,那么

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;

                        }

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;

                        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文