public static extern int StretchDIBits(HandleRef hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, byte[] lpBits, ref NativeMethods.BITMAPINFO_FLAT lpBitsInfo, int iUsage, int dwRop);
/// <summary> /// Call into native code to create compatible Device Independent Bitmap /// </summary> /// <param name="hdc">Source hdc</param> /// <param name="ulWidth">Bitmap width</param> /// <param name="ulHeight">Bitmap height</param> /// <param name="ppvBits">Returned bits</param> /// <returns>The handle to the new bitmap</returns> private int CreateCompatibleDIB(int hdc, int ulWidth, int ulHeight, ref int ppvBits) { int hbmRet = NativeMethods.Nullint; NativeMethods.BITMAPINFO_FLAT pbmi = new NativeMethods.BITMAPINFO_FLAT(); // // Validate hdc. // if (hdc == NativeMethods.Nullint) { throw new ArgumentNullException("hdc"); } if (NativeMethods.GetObjectType(hdc) != NativeMethods.OBJ_DC ) { throw new ArgumentException("hdc", "HDC must be screen DC!"); } if (FillBitmapInfo(hdc, ref pbmi)) { // // Change bitmap size to match specified dimensions. // pbmi.bmiHeader_biWidth = ulWidth; pbmi.bmiHeader_biHeight = ulHeight; if (pbmi.bmiHeader_biCompression == NativeMethods.BI_RGB) { pbmi.bmiHeader_biSizeImage = 0; } else { if ( pbmi.bmiHeader_biBitCount == 16 ) pbmi.bmiHeader_biSizeImage = ulWidth * ulHeight * 2; else if ( pbmi.bmiHeader_biBitCount == 32 ) pbmi.bmiHeader_biSizeImage = ulWidth * ulHeight * 4; else pbmi.bmiHeader_biSizeImage = 0; } pbmi.bmiHeader_biClrUsed = 0; pbmi.bmiHeader_biClrImportant = 0; // // Create the DIB section. Let Win32 allocate the memory and return // a pointer to the bitmap surface. // hbmRet = NativeMethods.CreateDIBSection(hdc, ref pbmi, NativeMethods.DIB_RGB_COLORS, ref ppvBits, NativeMethods.Nullint, 0); if ( hbmRet == NativeMethods.Nullint ) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } return hbmRet; }
public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int uStartScan, int cScanLines, byte[] lpvBits, ref NativeMethods.BITMAPINFO_FLAT bmi, int uUsage);