问题描述
我最近升级从ASP.NET到ASP.NET核心ASP.NET MVC应用程序。
I've recently upgraded an ASP.NET MVC application from ASP.NET to ASP.NET Core.
在我的控制器动作,我有一段代码这依赖于System.Drawing中创建一个配置文件图片
In my controller action, I had a piece of code that relied on System.Drawing to create a profile picture
using (FileStream stream = new FileStream(HttpContext.Server.MapPath($"~/Content/UserFiles/{AuthenticatedUser.Id.ToString()}.jpg"), FileMode.OpenOrCreate))
{
Image image = Image.FromStream(model.DisplayPicture.InputStream);
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
图片数据被发送到服务器为Base64编码的图像
The image data is posted to the server as a Base64 encoded image
由于没有 System.Drawing中
在.NET的核心,是否有任何其他库,可以实现这一点?
Since there's no System.Drawing
in .NET Core, are there any other libraries that can achieve this?
推荐答案
由于斯坦尼斯指出,目前的解决方案是在完整的.NET框架使用ASP.NET的核心。 System.Drawing中依赖于GDI +调用的,因此必然会到Windows。
As Stanislav pointed out the current solution is to use ASP.NET Core on the full .NET framework. System.Drawing relies on GDI+ calls an is therefore bound to Windows.
由Imazen图像调整的vNext版本将解决基于新imageflow项目这个问题。 System.Drawing中不应该在服务器环境中,如ASP.NET中使用(指出了的)。关于这一主题的一些背景知识上提供 。
The vNext Version of Image Resizer by Imazen will solve this problem based on the new imageflow project. System.Drawing should not be used in server environments like ASP.NET (pointed out on https://msdn.microsoft.com/en-us/library/system.drawing(v=vs.110).aspx). Some background on this topic is provided on https://github.com/imazen/Graphics-vNext.
我建议使用ImagerResizing当前版本4.0.5升级在一些个月(第一个稳定版本vNext为明年公布)。
I suggest to use the current version 4.0.5 of ImagerResizing and upgrade in some months (first stable vNext version is announced for next year).
这篇关于ASP.NET Core中的服务器端图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!