def __del__(self): try: if self._dc: gdi32.DeleteDC(self._dc) if self._bitmap: gdi32.DeleteObject(self._bitmap) except: pass
def _create_bitmap(self, width, height): self._black = gdi32.GetStockObject(BLACK_BRUSH) self._white = gdi32.GetStockObject(WHITE_BRUSH) if self._dc: gdi32.ReleaseDC(self._dc) if self._bitmap: gdi32.DeleteObject(self._bitmap) pitch = width * 4 data = POINTER(c_byte * (height * pitch))() info = BITMAPINFO() info.bmiHeader.biSize = sizeof(info.bmiHeader) info.bmiHeader.biWidth = width info.bmiHeader.biHeight = height info.bmiHeader.biPlanes = 1 info.bmiHeader.biBitCount = 32 info.bmiHeader.biCompression = BI_RGB self._dc = gdi32.CreateCompatibleDC(c_void_p()) self._bitmap = gdi32.CreateDIBSection(c_void_p(), byref(info), DIB_RGB_COLORS, byref(data), c_void_p(), 0) # Spookiness: the above line causes a "not enough storage" error, # even though that error cannot be generated according to docs, # and everything works fine anyway. Call SetLastError to clear it. kernel32.SetLastError(0) self._bitmap_data = data.contents self._bitmap_rect = RECT() self._bitmap_rect.left = 0 self._bitmap_rect.right = width self._bitmap_rect.top = 0 self._bitmap_rect.bottom = height self._bitmap_height = height if _debug_font: _debug('%r._create_dc(%d, %d)' % (self, width, height)) _debug('_dc = %r' % self._dc) _debug('_bitmap = %r' % self._bitmap) _debug('pitch = %r' % pitch) _debug('info.bmiHeader.biSize = %r' % info.bmiHeader.biSize)
def __del__(self): if self._dc: gdi32.DeleteDC(self._dc) if self._bitmap: gdi32.DeleteObject(self._bitmap)