CadEditor.UtilsGDI.ConvertBitmapToArray C# (CSharp) Метод

ConvertBitmapToArray() приватный статический Метод

private static ConvertBitmapToArray ( Bitmap bmp ) : ].ushort[][
bmp System.Drawing.Bitmap
Результат ].ushort[][
        private static ushort[][,] ConvertBitmapToArray(Bitmap bmp)
        {
            ushort[][,] array = new ushort[4][,];

            for (int i = 0; i < 4; i++)
                array[i] = new ushort[bmp.Width, bmp.Height];

            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            int nOffset = (bd.Stride - bd.Width * 4);

            unsafe
            {

                byte* p = (byte*)bd.Scan0;

                for (int y = 0; y < bd.Height; y++)
                {
                    for (int x = 0; x < bd.Width; x++)
                    {

                        array[3][x, y] = (ushort)p[3];
                        array[2][x, y] = (ushort)p[2];
                        array[1][x, y] = (ushort)p[1];
                        array[0][x, y] = (ushort)p[0];

                        p += 4;
                    }

                    p += nOffset;
                }
            }
            bmp.UnlockBits(bd);
            return array;
        }