void TryUpdateGraphics() { var winRect = Window.Rect; if (width != winRect.Width || height != winRect.Height) { width = winRect.Width; height = winRect.Height; buffer = new int[width * height]; if (hBitmap != IntPtr.Zero) { WinApi.DeleteObject(hBitmap); } hBitmap = WinApi.CreateBitmap(width, height, 1, 32, IntPtr.Zero); if (hBitmap == IntPtr.Zero) { throw new Exception(); } WinApi.SelectObject(memDC, hBitmap); } }
protected override void Dispose(bool disposing) { WinApi.DeleteObject(hBitmap); WinApi.DeleteDC(memDC); WinApi.ReleaseDC(Window.Handle, hdc); }