private void CreateImageDc(int width, int height, IntPtr hBmp) { IntPtr pHdc = IntPtr.Zero; pHdc = NativeMethodsToop.CreateDCA("DISPLAY", "", "", 0); _pHdc = NativeMethodsToop.CreateCompatibleDC(pHdc); if (hBmp != IntPtr.Zero) { _pBmp = hBmp; } else { _pBmp = NativeMethodsToop.CreateCompatibleBitmap(pHdc, width, height); } _pBmpOld = NativeMethodsToop.SelectObject(_pHdc, _pBmp); if (_pBmpOld == IntPtr.Zero) { ImageDestroy(); } else { _width = width; _height = height; } NativeMethodsToop.DeleteDC(pHdc); pHdc = IntPtr.Zero; }
private void ImageDestroy() { if (_pBmpOld != IntPtr.Zero) { NativeMethodsToop.SelectObject(_pHdc, _pBmpOld); _pBmpOld = IntPtr.Zero; } if (_pBmp != IntPtr.Zero) { NativeMethodsToop.DeleteObject(_pBmp); _pBmp = IntPtr.Zero; } if (_pHdc != IntPtr.Zero) { NativeMethodsToop.DeleteDC(_pHdc); _pHdc = IntPtr.Zero; } }