c#中将8Mono像素数据数组转换为24位图像

时间:2021-02-13 06:30:44

标签: c# .net image-processing type-conversion

我正在使用 mvfox-igc 相机 sdk 从该相机获取图像我的问题是我有 mono8 图像的字节数组,我想将该像素数据转换为我的编程语言的 24 位图像 任何人都可以帮助我,请我的代码看起来像这样,但没有正常工作

            processedBitmap = new Bitmap(data.request.imageWidth.read(),data.request.imageHeight.read(),PixelFormat.Format24bppRgb);
            unsafe
            {
                BitmapData bitmapData = processedBitmap.LockBits(new Rectangle(0, 0, processedBitmap.Width, processedBitmap.Height), ImageLockMode.ReadWrite, processedBitmap.PixelFormat);

                int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(processedBitmap.PixelFormat) / 8;
                int heightInPixels = bitmapData.Height;
                int widthInBytes = bitmapData.Width * bytesPerPixel;
                byte* PtrFirstPixel = (byte*)bitmapData.Scan0;
                byte* firstby = (byte*)data.request.imageData.read();
                int indexx=0;
                Parallel.For(0, heightInPixels, y =>
                {
                    byte* currentLine = PtrFirstPixel + (y * bitmapData.Stride);
                    for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
                    {
                        currentLine[x] = firstby[indexx];//((byte*)data.request.imageData.read())[0];//(byte)oldBlue;
                        currentLine[x + 1] = firstby[indexx];//((byte*)data.request.imageData.read())[0];//(byte)oldGreen;
                        currentLine[x + 2] = firstby[indexx];//((byte*)data.request.imageData.read())[0];//(byte)oldRed;
                        indexx = indexx + 1;
                    }
                });
                processedBitmap.UnlockBits(bitmapData);
                processedBitmap.Save("bmp.jpg");

0 个答案:

没有答案