在WinForms应用程序中的PictureBox中显示RAW RGB字节数组

时间:2017-01-22 01:06:39

标签: c# winforms rgb picturebox

我有一个附加的.rgb文件。这是我通过其他软件验证的有效rgb文件。据我所知,这是一个原始的RGB数据文件。

我需要将文件加载到byte []并在PictureBox中显示它。 从我在这里的所有搜索中,我找到了这个看起来正确但适用于其他人的解决方案。不幸的是,它没有显示任何内容:

                    string imgPath = Path.Combine(mInstallPath, "squirrel-720x576x50.rgb\\squirrel-720x576x50.rgb");
                byte[] imageData = File.ReadAllBytes(imgPath); 

                using (var bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb))
                {
                    BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,
                                                                    bmp.Width,
                                                                    bmp.Height),
                                                                    ImageLockMode.WriteOnly,
                                                                    bmp.PixelFormat);
                    Marshal.Copy(imageData, 0, bmpData.Scan0, width * height * 3);//imageData.Length);
                    //bmpSource.CopyPixels((Int32Rect.Empty, bmpData.Scan0, bmpData.Height * bmpData.Stride, bmpData.Stride);
                    bmp.UnlockBits(bmpData);
                    pictureBox.Image = bmp;
                }

为什么我的pictureBox中没有显示任何内容?

0 个答案:

没有答案
相关问题