using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

using (var bitmap = new Bitmap(4, 2, PixelFormat.Format8bppIndexed))
{

//bitmap.Palette.Entries[0] = Color.Red;
//bitmap.Palette.Entries[1] = Color.Black;
var data = bitmap.LockBits(new Rectangle(0, 0, 4, 2), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
var bytes = new byte[] { 1, 1, 1, 1, 2, 3, 2, 4 };
// 复制数据到位图
Marshal.Copy(bytes, 0, data.Scan0, bytes.Length);
// 解锁位图
bitmap.UnlockBits(data);
bitmap.Save("D:/output.bmp", ImageFormat.Bmp);

}

标签: none

添加新评论