wx.MemoryDC

Inheritance diagram for wx.MemoryDC:



Description

A memory device context provides a means to draw graphics onto a bitmap. When drawing in to a mono-bitmap, using wx.WHITE, wx.WHITE_PEN and wx.WHITE_BRUSH will draw the background colour (i.e. 0) whereas all other colours will draw the foreground colour (i.e. 1).

See also

wx.Bitmap, wx.DC

Derived From

Remarks

A bitmap must be selected into the new memory DC before it may be used for anything.

Typical usage is as follows:

# Create a memory DC
temp_dc = wx.MemoryDC()
temp_dc.SelectObject(test_bitmap)

# We can now draw into the memory DC...
DrawSomething(temp_dc)

# Copy from this DC to another DC.
old_dc.Blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, temp_dc, 0, 0)

temp_dc.SelectObject(wx.NullBitmap)

Note

Note that the memory DC must be deleted (or the bitmap selected out of it) before a bitmap can be reselected into another memory DC.

Class API

Methods

__init__(bitmap=wx.NullBitmap)

Constructs a new memory device context.

Use the Ok member to test whether the constructor was successful in creating a usable device context. If a bitmap is not given to this constructor then don’t forget to select a bitmap into the DC before drawing on it.

Parameters:


Returns:

wx.MemoryDC


SelectObject(bitmap)

Works exactly like SelectObjectAsSource but this is the function you should use when you select a bitmap because you want to modify it, e.g. drawing on this DC.

Be careful to use this function and not SelectObjectAsSource when you want to modify the bitmap you are selecting otherwise you may incurr in some problems related to wx.Bitmap being a reference counted object.

Parameters:

See also

wx.DC.DrawBitmap


SelectObjectAsSource(bitmap)

Selects the given bitmap into the device context, to use as the memory bitmap. Selecting the bitmap into a memory DC allows you to draw into the DC (and therefore the bitmap) and also to use wx.DC.Blit to copy the bitmap to a window. For this purpose, you may find wx.DC.DrawIcon easier to use instead.

If the argument is wx.NullBitmap (or some other uninitialised wx.Bitmap) the current bitmap is selected out of the device context, and the original bitmap restored, allowing the current bitmap to be destroyed safely.

Parameters:

See also

SelectObject