[英].Net Core unable to use Bitmap
I am working on a Web Service using .Net Core 2.1.我正在使用 .Net Core 2.1 开发 Web 服务。
I have a byte array containing all pixels values (in grey scale), a width, a height.我有一个包含所有像素值(灰度)、宽度、高度的字节数组。 I want to create a bitmap from theses parameters.
我想从这些参数创建一个位图。
There is my code (from a working .Net Framework 4 project) :有我的代码(来自一个有效的 .Net Framework 4 项目):
public FileResult PostSealCryptItem(Byte[] matrix, int width, int height)
{
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
bmp.SetPixel(x, y, Color.FromArgb(ToArgb(matrix, x, y)));
Byte[] data = BitmapToByteArray(bmp);
FileContentResult result = new FileContentResult(data , "image/png");
return result;
}
But in .NET Core, I've the error :但是在 .NET Core 中,我遇到了错误:
The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)
找不到类型或命名空间名称“位图”(您是否缺少 using 指令或程序集引用?)
I've try to add reference to System.Drawing but it did not work.我尝试添加对 System.Drawing 的引用,但没有奏效。
Install Nuget Package System.Drawing.Common安装 Nuget 包 System.Drawing.Common
It is no longer included with .net core and must be added manually.它不再包含在 .net core 中,必须手动添加。
You can use ImageSharp instead of System.Drawing您可以使用 ImageSharp 而不是 System.Drawing
https://github.com/SixLabors/ImageSharp https://github.com/SixLabors/ImageSharp
Nuget console Nuget 控制台
Install-Package SixLabors.ImageSharp -Version 1.0.0-beta0005
Aspose.Drawing is a drop-in cross-platform replacement for System.Drawing. Aspose.Drawing是 System.Drawing 的跨平台替代品。 The library is fully managed and supports Web Services using .Net Core 2.1.
该库是完全托管的,并支持使用 .Net Core 2.1 的 Web 服务。 (I'm one of the developers.)
(我是开发人员之一。)
有一个 NuGet 包而不是 System.Drawing,你可以使用它
Install-Package System.Drawing.Common
这个对我dotnet add package System.Drawing.Common --version 5.0.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.