public BitmapRenderer(IntPtr dibHandle) { _dibHandle = dibHandle; _bitmapPointer = Kernel32Native.GlobalLock(dibHandle); _bitmapInfo = new BitmapInfoHeader(); Marshal.PtrToStructure(_bitmapPointer, _bitmapInfo); log.Debug(_bitmapInfo.ToString()); _rectangle = new Rectangle(); _rectangle.X = _rectangle.Y = 0; _rectangle.Width = _bitmapInfo.Width; _rectangle.Height = _bitmapInfo.Height; if (_bitmapInfo.SizeImage == 0) { _bitmapInfo.SizeImage = ((((_bitmapInfo.Width * _bitmapInfo.BitCount) + 31) & ~31) >> 3) * _bitmapInfo.Height; } // The following code only works on x86 Debug.Assert(Marshal.SizeOf(typeof(IntPtr)) == 4); int pixelInfoPointer = _bitmapInfo.ClrUsed; if ((pixelInfoPointer == 0) && (_bitmapInfo.BitCount <= 8)) { pixelInfoPointer = 1 << _bitmapInfo.BitCount; } pixelInfoPointer = (pixelInfoPointer * 4) + _bitmapInfo.Size + _bitmapPointer.ToInt32(); _pixelInfoPointer = new IntPtr(pixelInfoPointer); }