Esempio n. 1
0
        protected void CreateDIBSection(int cx, int cy, int ppm_x, int ppm_y, short BitCount)
        {
            IntPtr hDC = WinInvoke32.GetDC(IntPtr.Zero);

            if(hDC.Equals(IntPtr.Zero)) return;

            IntPtr pvBits = IntPtr.Zero;
            BITMAPINFO BitmapInfo = new BITMAPINFO();
            BitmapInfo.bmiHeader = new BITMAPINFOHEADER();

            BitmapInfo.bmiHeader.biSize               = 40;
            BitmapInfo.bmiHeader.biWidth              = cx;
            BitmapInfo.bmiHeader.biHeight             = cy;
            BitmapInfo.bmiHeader.biPlanes             = 1;
            BitmapInfo.bmiHeader.biBitCount           = BitCount;
            BitmapInfo.bmiHeader.biCompression        = WinInvoke32.BI_RGB;
            BitmapInfo.bmiHeader.biSizeImage          = 0;
            BitmapInfo.bmiHeader.biXPelsPerMeter      = ppm_x;
            BitmapInfo.bmiHeader.biYPelsPerMeter      = ppm_y;
            BitmapInfo.bmiHeader.biClrImportant       = 0;
            BitmapInfo.bmiHeader.biClrUsed            = 0;

            m_hBitmap = WinInvoke32.CreateDIBSection(hDC, ref BitmapInfo, 0, pvBits, IntPtr.Zero, 0);

            if(m_hBitmap.Equals(IntPtr.Zero))
            {
                WinInvoke32.ReleaseDC(IntPtr.Zero, hDC);
                return;
            }
            else
            {
                IntPtr hdcMemory = WinInvoke32.CreateCompatibleDC(hDC);
                IntPtr hbmpOld = WinInvoke32.SelectObject( hdcMemory, m_hBitmap );
                RECT rc;

                rc.left = rc.top = 0;
                rc.right = cx;
                rc.bottom = cy;
                IntPtr hBrush = WinInvoke32.GetStockObject(WinInvoke32.WHITE_BRUSH);
                WinInvoke32.FillRect(hdcMemory, ref rc, hBrush);
                WinInvoke32.SelectObject(hdcMemory, hbmpOld);
                WinInvoke32.DeleteDC(hdcMemory);
            }

            WinInvoke32.ReleaseDC(IntPtr.Zero, hDC);
        }
Esempio n. 2
0
 public static extern IntPtr CreateDIBSection(IntPtr hDC, ref BITMAPINFO pBitmapInfo, int un, IntPtr lplpVoid, IntPtr handle, int offset);