我刚刚开始使用ImageResizer通过下面的网站代码为图像创建缩略图。
private void CreateThumbnail()
{
Dictionary<string, string> versions = new Dictionary<string, string>();
//Define the versions to generate
versions.Add("_thumb", "width=100&height=100&crop=auto&format=jpg"); //Crop to square thumbnail
versions.Add("_medium", "maxwidth=100&maxheight=100&format=jpg"); //Fit inside 400x400 area, jpeg
versions.Add("_large", "maxwidth=1900&maxheight=1900&format=jpg"); //Fit inside 1900x1200 area
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
{
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
//Get the physical path for the uploads folder and make sure it exists
string uploadFolder = MapPath("~/Images");
if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder);
//Generate each version
foreach (string suffix in versions.Keys)
{
//Generate a filename (GUIDs are best).
string fileName = Path.Combine(uploadFolder, "AssetID" + suffix);
//Let the image builder add the correct extension based on the output file type
fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
}
}
}
但是,当我将此代码应用于Pdf时,它崩溃并显示错误“文件可能已损坏,为空,或者可能包含尺寸大于65,535像素的PNG图片”。
我需要进行哪些更改才能确定Pdf的大小?我仔细阅读了他们的文档,尽管看起来它会从Pdf创建缩略图,但示例均使用图像。
这是包含PdfRenderer的插件的列表
最佳答案
没有安装PdfiumRenderer或PdfRenderer插件(无论您选择哪个)。因此,主解码器无法解码图像。
您必须安装PDF插件才能正常工作。
PdfiumRenderer是两者中最好的。
见http://imageresizing.net/docs/v4/plugins/pdfiumrenderer