public MyBitmapFile(int nWidth, int nHeight, IntPtr pImage)
        {
            m_fileHeaderBitmap = new BITMAPFILEHEADER();
            m_infoBitmap       = new BITMAPINFO();

            int length = m_fileHeaderBitmap.SizeOfBFH + m_infoBitmap.SizeOfBI + nWidth * nHeight;

            m_fileHeaderBitmap.BfSize       = (uint)length;
            m_fileHeaderBitmap.BfOffBits    = (uint)(m_fileHeaderBitmap.SizeOfBFH + m_infoBitmap.SizeOfBI);
            m_infoBitmap.bmiHeader.BiWidth  = nWidth;
            m_infoBitmap.bmiHeader.BiHeight = nHeight;

            m_BmpData = new byte[length];
            byte[] TempData = m_fileHeaderBitmap.GetByteData();
            Array.Copy(TempData, 0, m_BmpData, 0, TempData.Length);
            int offset = TempData.Length;

            TempData = m_infoBitmap.bmiHeader.GetByteData();
            Array.Copy(TempData, 0, m_BmpData, offset, TempData.Length);
            offset  += TempData.Length;
            TempData = m_infoBitmap.bmiColors.GetGRBTableByteData();
            Array.Copy(TempData, 0, m_BmpData, offset, TempData.Length);
            offset += TempData.Length;
            //rotate image
            byte[] pRotateImage = new byte[nWidth * nHeight];
            int    nImgOffset   = 0;
            IntPtr pPtr;

            for (int iCyc = 0; iCyc < nHeight; iCyc++)
            {
                pPtr = (IntPtr)(pImage.ToInt32() + (nHeight - iCyc - 1) * nWidth);
                Marshal.Copy(pPtr, pRotateImage, nImgOffset, nWidth);
                //Array.Copy(pImage, (nHeight - iCyc - 1) * nWidth, pRotateImage, nImgOffset, nWidth);
                nImgOffset += nWidth;
            }
            Array.Copy(pRotateImage, 0, m_BmpData, offset, pRotateImage.Length);
            TempData     = null;
            pRotateImage = null;
        }
 public MyBitmapFile()
 {
     m_fileHeaderBitmap = new BITMAPFILEHEADER();
     m_infoBitmap       = new BITMAPINFO();
 }