我正在使用图像调整大小包-asp.net核心(剃刀页面)应用程序中的Lazziya.ImageResize v3上传图像,然后将其调整为600x400尺寸。
上传的图像尺寸为1181x 1575像素(宽x高)。
上传图像的代码的第一部分工作正常,但是在Lazziya.ImageResize函数ResizeUploadedFile(filePath);
中生成了错误。
错误是由img.ScaleByWidth(600).SaveAs(path, 95);
生成的
即使我使用img.ScaleAndCrop(600,400).SaveAs(path);
,它也会显示相同的错误。
我不确定为什么它会生成此错误,因为我正在按照文档使用函数
private string ProcessUploadedFile()
{
string uniqueFileName = null;
string filePath = null;
if (NewsImageForUpload != null)
{
string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images/news");
uniqueFileName = Guid.NewGuid().ToString() + "_" + NewsImageForUpload.FileName;
filePath = Path.Combine(uploadsFolder, uniqueFileName);
// string fullPath = filePath.ToString();
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
NewsImageForUpload.CopyTo(fileStream);
}
}
ResizeUploadedFile(filePath);
return uniqueFileName;
}
private void ResizeUploadedFile(string filePath)
{
// string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images/news");
// filePath = Path.Combine(uniqueFileName, uniqueFileName);
string path = Path.Combine(filePath);
using (var img = Image.FromFile(path))
{
img.ScaleByWidth(600).SaveAs(path, 95);
}
}
http://demo.ziyad.info/en/ImageResize
错误详细信息*
An unhandled exception occurred while processing the request.
ExternalException: A generic error occurred in GDI+.
System.Drawing.Image.Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
Stack Query Cookies Headers Routing
ExternalException: A generic error occurred in GDI+.
System.Drawing.Image.Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
LazZiya.ImageResize.SaveImage.SaveAs(Image img, string path, int quality)
BookListRazor.Pages.Admin.News.NewsCreateModel.ResizeUploadedFile(string filePath) in NewsCreate.cshtml.cs
img.ScaleByWidth(600).SaveAs(path, 95);
BookListRazor.Pages.Admin.News.NewsCreateModel.ProcessUploadedFile() in NewsCreate.cshtml.cs
ResizeUploadedFile(filePath);
BookListRazor.Pages.Admin.News.NewsCreateModel.OnPost() in NewsCreate.cshtml.cs
News.NewsImage = ProcessUploadedFile();
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Convert<T>(object taskAsObject)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Execute(object receiver, object[] arguments)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)