如何将system.drawing.image转换成Sixlabors.imagesharp.pixelformats.Rgba32
时间: 2023-11-26 15:05:49 浏览: 211
可以使用ImageSharp库进行转换,示例代码如下:
```
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Drawing;
public Rgba32[,] ConvertToRgba32(Bitmap bitmap)
{
using (var image = Image.Load(bitmap))
{
var pixelBuffer = image.Frames[0].PixelBuffer;
var pixelWidth = image.Width;
var pixelHeight = image.Height;
var bitmapPixels = new Rgba32[pixelHeight, pixelWidth];
for (var y = 0; y < pixelHeight; y++)
{
for (var x = 0; x < pixelWidth; x++)
{
bitmapPixels[y, x] = pixelBuffer.GetRowSpan(y)[x].ToRgba32();
}
}
return bitmapPixels;
}
}
```
该函数将给定的`Bitmap`对象转换为`Rgba32`像素格式的二维数组,并返回该数组。
阅读全文