.Net Core无法使用位图

时间:2019-01-14 11:08:43

标签: c# .net-core .net-core-2.1

我正在使用.Net Core 2.1开发Web服务。

我有一个字节数组,其中包含所有像素值(灰度),宽度和高度。我想根据这些参数创建位图。

有我的代码(来自正在运行的.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;
}

但是在.NET Core中,我出现了错误:

  

找不到类型或名称空间名称“位图”(您是否缺少using指令或程序集引用?)

我尝试添加对System.Drawing的引用,但是它不起作用。

3 个答案:

答案 0 :(得分:3)

安装Nuget软件包System.Drawing.Common

.net核心不再包含它,必须手动添加。

答案 1 :(得分:2)

您可以使用ImageSharp代替System.Drawing

https://github.com/SixLabors/ImageSharp

Nuget控制台

Install-Package SixLabors.ImageSharp -Version 1.0.0-beta0005

答案 2 :(得分:0)

Aspose.Drawing是System.Drawing的跨平台替代品。该库受到完全管理,并使用.Net Core 2.1支持Web服务。 (我是开发人员之一。)