public System.Drawing.Bitmap GetFrameBuffer()
        {
            ushort widthInWords;
            ushort heightInPixels;
            uint[] buf;

            System.Drawing.Bitmap bmp = null;


            System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.DontCare;

            if (GetFrameBuffer(out widthInWords, out heightInPixels, out buf))
            {
                CLRCapabilities.LCDCapabilities lcdCaps = Capabilities.LCD;

                int pixelsPerWord = 32 / (int)lcdCaps.BitsPerPixel;

                System.Diagnostics.Debug.Assert(heightInPixels == lcdCaps.Height);
                System.Diagnostics.Debug.Assert(widthInWords == (lcdCaps.Width + pixelsPerWord - 1) / pixelsPerWord);

                System.Drawing.Color[] colors = null;

                switch (lcdCaps.BitsPerPixel)
                {
                    case 1:
                        pixelFormat = System.Drawing.Imaging.PixelFormat.Format1bppIndexed;
                        colors = new System.Drawing.Color[] { System.Drawing.Color.White, System.Drawing.Color.Black };
                        Adjust1bppOrientation(buf);
                        break;
                    case 4:
                    case 8:
                        //Not tested
                        int cColors = 1 << (int)lcdCaps.BitsPerPixel;

                        pixelFormat = (lcdCaps.BitsPerPixel == 4) ? System.Drawing.Imaging.PixelFormat.Format4bppIndexed : System.Drawing.Imaging.PixelFormat.Format8bppIndexed;

                        colors = new System.Drawing.Color[cColors];

                        for (int i = 0; i < cColors; i++)
                        {
                            int intensity = 256 / cColors * i;
                            colors[i] = System.Drawing.Color.FromArgb(intensity, intensity, intensity);
                        }

                        break;
                    case 16:
                        pixelFormat = System.Drawing.Imaging.PixelFormat.Format16bppRgb565;
                        break;
                    default:
                        System.Diagnostics.Debug.Assert(false);
                        return null;
                }

                System.Drawing.Imaging.BitmapData bitmapData = null;

                try
                {
                    bmp = new System.Drawing.Bitmap((int)lcdCaps.Width, (int)lcdCaps.Height, pixelFormat);
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, (int)lcdCaps.Width, (int)lcdCaps.Height);

                    if (colors != null)
                    {
                        System.Drawing.Imaging.ColorPalette palette = bmp.Palette;
                        colors.CopyTo(palette.Entries, 0);
                        bmp.Palette = palette;
                    }

                    bitmapData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, pixelFormat);
                    IntPtr data = bitmapData.Scan0;

                    unsafe
                    {
                        fixed (uint* pbuf = buf)
                        {
                            uint* src = (uint*)pbuf;
                            uint* dst = (uint*)data.ToPointer();

                            for (int i = buf.Length; i > 0; i--)
                            {
                                *dst = *src;
                                dst++;
                                src++;
                            }

                        }
                    }
                }

                finally
                {
                    if (bitmapData != null)
                    {
                        bmp.UnlockBits(bitmapData);
                    }
                }
            }

            return bmp;
        }