Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net ImageResizer-进程无法访问该文件,因为其他进程正在使用该文件_Asp.net_Imageresizer - Fatal编程技术网

Asp.net ImageResizer-进程无法访问该文件,因为其他进程正在使用该文件

Asp.net ImageResizer-进程无法访问该文件,因为其他进程正在使用该文件,asp.net,imageresizer,Asp.net,Imageresizer,此行抛出错误:ImageBuilder.Current.Build(imgURL、imgURL、resizeImg) 知道为什么吗 public void setImgSize(string controlId, string filename) { decimal currentWidth = 0; decimal currentHeight = 0; int maxFileWidth = 600; int maxFileHeight = 600; bo

此行抛出错误:
ImageBuilder.Current.Build(imgURL、imgURL、resizeImg)

知道为什么吗

public void setImgSize(string controlId, string filename)
{
    decimal currentWidth = 0;
    decimal currentHeight = 0;
    int maxFileWidth = 600;
    int maxFileHeight = 600;
    bool imageExists = false;
    string imgURL = "~/SODocs/" + SONum + "/" + filename;
    string imgPath = Server.MapPath(imgURL);
    if (File.Exists(imgPath))
    {
        imageExists = true;
        System.Drawing.Image imgFile = System.Drawing.Image.FromFile(imgPath);
        Image imgControl = FindControl(controlId) as Image;
        int maxDisplayWidth = 273;
        int maxDisplayHeight = 200;
        currentWidth = Convert.ToDecimal(imgFile.Width);
        currentHeight = Convert.ToDecimal(imgFile.Height);
        int newDisplayWidth = 0;
        int newDisplayHeight = 0;
        int paddingHeight = 0;

        if (currentHeight > currentWidth)
        {
            imgControl.Height = maxDisplayHeight;
            newDisplayWidth = Convert.ToInt32((maxDisplayHeight / currentHeight) * currentWidth);
            imgControl.Width = newDisplayWidth;
            imgControl.Style.Add("margin", "0 auto");
        }
        else if (currentWidth > currentHeight)
        {
            newDisplayHeight = Convert.ToInt32((maxDisplayWidth / currentWidth) * currentHeight);

            if (newDisplayHeight > maxDisplayHeight)
            {
                // set newWidth based on maxHeight
                newDisplayWidth = Convert.ToInt32((maxDisplayHeight / currentHeight) * currentWidth);
                imgControl.Width = newDisplayWidth;
                imgControl.Style.Add("margin", "0 auto");
            }
            else
            {
                imgControl.Width = maxDisplayWidth;
            }

            paddingHeight = maxDisplayHeight - newDisplayHeight;
            imgControl.Style.Add("padding-top", paddingHeight.ToString() + "px");
        }

        imgControl.ImageUrl = imgURL;
        imgFile.Dispose();
        imgFile = null;

        if (imageExists)
        {
            // resize the image file
            if (currentWidth > maxFileWidth | currentHeight > maxFileHeight)
            {
                var resizeImg = new ResizeSettings();
                resizeImg.MaxWidth = maxFileWidth;
                resizeImg.MaxHeight = maxFileHeight;

                ImageBuilder.Current.Build(imgURL, imgURL, resizeImg);

            }
        }
    }
}
您正在打开该文件以便自己单独读取,但希望ImageResizer稍后能够写入该文件。System.Drawing无法正确处理文件锁定,并且.Dispose()不足以处理内存泄漏或遇到的文件访问问题。 我建议复习一下ImageResizer的用法


您在这里试图实现的目标很可能是可以实现的。

也许是一个愚蠢的问题,但您是否在Photoshop或类似的软件中打开了图像?我也知道,当我将文件ftp到服务器时,上传“挂起”Hmmm时会出现这种错误。。。好像是这样的。不过,我并没有把它明目张胆地打开。也许背景中有什么东西抓住了它。