C# byte[] ARGB保存为png
时间: 2023-12-07 10:03:08 浏览: 25
你可以使用C#中的System.Drawing命名空间来将byte[] ARGB保存为PNG格式的图片。下面是示例代码:
```
using System.Drawing;
using System.Drawing.Imaging;
// 将byte[] ARGB保存为PNG格式的图片
public void SaveAsPNG(byte[] argb, int width, int height, string filename)
{
// 创建Bitmap对象
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
// 将byte[] ARGB写入Bitmap对象
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
System.Runtime.InteropServices.Marshal.Copy(argb, 0, bmpData.Scan0, argb.Length);
bmp.UnlockBits(bmpData);
// 将Bitmap对象保存为PNG格式的图片
bmp.Save(filename, ImageFormat.Png);
}
```
使用示例:
```
byte[] argb = new byte[width * height * 4]; // 假设已经初始化为ARGB数据
string filename = "test.png";
SaveAsPNG(argb, width, height, filename);
```