ImageResizer源参数未被接受

时间:2015-05-20 03:55:28

标签: c# asp.net imageresizer

我正在尝试从文件夹中循环jpeg图像并使用以下方法将其提供给dll,但它会抛出此错误 Source可能只是字符串,VirtualFile,IVirtualBitmapFile,HttpPostedFile,HttpPostedFileBase,Bitmap,Image或Stream的实例。 参数名称:source

 foreach(FileInfo file in tempFolder.GetFiles())
        if (file.Exists == true)
        { //Skip unused file controls.

            //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
            //Destination paths can have variables like <guid> and <ext>, or 
            //even a santizied version of the original filename, like <filename:A-Za-z0-9>
            ImageResizer.ImageJob i = new ImageResizer.ImageJob(file, uploadFolder + "/<guid>.<ext>", new ImageResizer.ResizeSettings(
                        "width=2000;height=2000;format=jpg;mode=max"));
            i.CreateParentDirectory = true; //Auto-create the uploads directory.
            i.Build();
        }
        browser.Attributes["multiple"] = "multiple";
        Page.Response.Redirect(Page.Request.Url.ToString(), true);
    }

1 个答案:

答案 0 :(得分:2)

ImageRsizer.ImageJob接受文件路径作为参数。您需要传递FileInfo属性,而不是提供FullName对象。即:

ImageResizer.ImageJob i = new ImageResizer.ImageJob(file.FullName, uploadFolder + "/<guid>.<ext>", new ImageResizer.ResizeSettings(
                    "width=2000;height=2000;format=jpg;mode=max"));