c#让颜色不起作用

时间:2015-01-28 06:12:43

标签: c# bmp

在翻译图片中的字节数组时,我希望接收每种颜色并添加到列表中,但它还没有结果显示接收颜色。试过不同的变种。

public unsafe static Bitmap RgbToBitmapQ(byte[, ,] rgb)
        {
            int width = rgb.GetLength(2),
                height = rgb.GetLength(1);
            Bitmap result = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            BitmapData bd = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly,
                PixelFormat.Format24bppRgb);
            try
            {
                byte* curpos;
                fixed (byte* _rgb = rgb)
                {
                    byte* _r = _rgb, _g = _rgb + 1, _b = _rgb + 2;
                    for (int h = 0; h < height; h++)
                    {
                        curpos = ((byte*)bd.Scan0) + h * bd.Stride;
                        for (int w = 0; w < width; w++)
                        {
                            *(curpos++) = *_b; _b += 3;
                            *(curpos++) = *_g; _g += 3;
                            *(curpos++) = *_r; _r += 3;

                            c = Color.FromArgb(*_r, *_g, *_b);//incorrect
                        }
                    }
                }
            }
            finally
            {
                result.UnlockBits(bd);
            }
            return result;
        }

0 个答案:

没有答案