我将会收到一些原始数据并储存在字节数组中,每2个字节是一个像素值(16 bits/px)。首先,该数组将包含100x100*2个字节(足够存储100x100像素图像)。我想在窗口中显示这些数据。最终,我想用新数据刷新图像,让它看起来像一个视频流。不需要严格的帧率。如何完成这个任务?是否有C#的代码示例?
编辑: 在一些建议和阅读了数十个类似问题的回答之后,我仍然无法解决问题。这是我尝试做的事情的一般想法,但图片没有显示在表格上。我的实现有什么具体问题以及如何解决?
// array of data I collected
byte[] dataArray = new byte[100 * 100 * 2];
//create a pointer to the data
IntPtr hglobal = Marshal.AllocHGlobal(100 * 100 * 2);
// copy my array to global
Marshal.Copy(dataArray, 0, hglobal, dataArray.Length);
// create a bitmap: 100x100 pixels, 2bytes/pixel, 16bitgrayscale
Bitmap newBitmap = new Bitmap(100, 100, 2 * 100, PixelFormat.Format16bppGrayScale, hglobal);
// display bitmap
pictureBox1.Image = newBitmap;
// free the memory
Marshal.FreeHGlobal(hglobal);
Bitmap.SetPixel()
吗? - MahanGMFormat48bppRgb
。 - Jony Adamit