我正在使用 .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 中,我遇到了错误:
找不到类型或命名空间名称“Bitmap”(是否缺少 using 指令或程序集引用?)
我尝试添加对 System.Drawing 的引用,但没有成功。
Bitmap
是其一部分System.Drawing
它包含在.Net Framework 中。
它不再包含在 .net core 中,必须手动添加。
安装 Nuget 包System.Drawing.Common
通过在 Visual Studio 中右键单击您的项目并选择Manage Nuget Packages
In the Nuget Package manager, click on the Browse Tab
, search for System.Drawing.Common
in the top and it should be the first Package, official by Microsoft. It will work just as in .Net Framework:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)