c# - Generate an image from an HTML code/file in .NET Core 2.x Console Application?
问题描述
I've currently a problem with the NReco.ImageGenerator in a .NET Core 2.x console application that I can't get an image because of course, the console application is not web service at all.
My question now is: Is there a way to use a somehow web service in a console application so I can generate an image from an HTML code/file or is there any other solution to generate an image from HTML code/file in a .NET Core 2.x console application?
Edit
It works on .NET Standard but not on .NET Core.
var html = string.Format("<h1>Hello World!</h1>");
var converter = new HtmlToImageConverter // Exception happens here
{
Width = 250,
Height = 70
};
var bytes = converter.GenerateImage(html, NReco.ImageGenerator.ImageFormat.Png);
Exception:
System.TypeLoadException: Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at NReco.ImageGenerator.HtmlToImageConverter..ctor()
at SESL.Modules.SESL.User.UserImage() in E:\Source\SESL-Discord\SESL\Modules\SESL\User.cs:line 36
解决方案
我发现NReco.ImageGenerator不支持 .NET Core,对于 .NET Core 我需要支付 LT 版本。但我发现了另一个 NuGet 包,它以某种方式做同样的事情,但我需要自己绘制图像。因此,替代方案是Magick.NET
推荐阅读
- objective-c - 如何以编程方式隐藏mac应用程序中的所有应用程序?
- firebase - Cloud firestore '!=' query
- c++ - Why is std::launder a constexpr function?
- wordpress - 如何为 Wordpress 创建 Single.php
- android - 如何将数据放入 MPAndroidChart 的饼图
- javascript - Angular Child Component 未在父数据更改时呈现
- kubernetes - 具有不同 CPU 配置的 Kubernetes 集群
- erlang - 降级 Erlang/OTP 后加载/重新编译 Rebar 模块
- json - 参数类型“x”不能分配给参数类型“x”
- c - 将 GCC 链接到外部库?