我正在尝试将我编写的代码从 .NET Framework 4.7.2 移植到 .NET Standard 2.0。该项目高度依赖System.Drawing.Bitmap对象来处理图像数据,主要来自System.IO.Stream对象。有什么方法可以让我移植此代码而无需重写当前使用位图的所有内容?
我已经研究过其他问题,所以我知道 .NET Standard 和 Bitmap 相处得不好,但我想知道是否有解决方法可以让我在花一个月的时间重写依赖于 .NET Standard 和 Bitmap 的代码之前保留现有代码在Bitmap。
有问题的代码主要集中在图像编辑和处理上。这是一个应该反转图像的函数。
Bitmap bmp;
...
public void Invert()
{
unsafe
{
BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, Bitmap.Width, Bitmap.Height), ImageLockMode.ReadWrite, Bitmap.PixelFormat);
int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(Bitmap.PixelFormat) / 8;
int heightInPixels = bitmapData.Height;
int widthInBytes = bitmapData.Width * bytesPerPixel;
byte* ptrFirstPixel = (byte*)bitmapData.Scan0;
for (int y = 0; y < heightInPixels; y++)
{
byte* currentLine = …Run Code Online (Sandbox Code Playgroud)