ASP.NET Core中的服务器端图形 [英] Server-side graphics in ASP.NET Core

查看:548
本文介绍了ASP.NET Core中的服务器端图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级从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

data:image/png;base64,....

由于没有 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中使用(指出了的 https://msdn.microsoft.com/en-us/library/system.drawing(v = vs.110)的.aspx )。关于这一主题的一些背景知识上提供 https://github.com/imazen/Graphics-vNext

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中的服务器端图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆