byte[]
ピクセル数と幅と高さがある場合は、フォーマットもわかっているため、ビットマップにバイトを書き込むために使用できますBitmapData
。次に例を示します。
//Your actual bytes
byte[] bytes = {255, 0, 0, 0, 0, 255};
var width = 2;
var height = 1;
//Make sure to clean up resources
var bitmap = new Bitmap(width, height);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
Marshal.Copy(bytes, 0, data.Scan0, bytes.Length);
bitmap.UnlockBits(data);
これは非常に高速な操作です。
少なくとも、C# ファイルの先頭に次の 3 つの名前空間をインポートする必要があります。
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;