utils.bitmaprenderingcontext

Provide a simple context class to support canvas.get_context('bitmap').

class rendercanvas.utils.bitmaprenderingcontext.BitmapRenderingContext(canvas, present_methods)

A context that supports rendering by generating grayscale or rgba images.

This is inspired by JS get_context('bitmaprenderer') which returns a ImageBitmapRenderingContext. It is a relatively simple context to implement, and provides a easy entry to using rendercanvas.

property canvas

The associated canvas object.

present()

Allow RenderCanvas to present the bitmap. Don’t call this yourself.

set_bitmap(bitmap)

Set the rendered bitmap image.

Call this in the draw event. The bitmap must be an object that can be conveted to a memoryview, like a numpy array. It must represent a 2D image in either grayscale or rgba format, with uint8 values

rendercanvas.utils.bitmaprenderingcontext.rendercanvas_context_hook(canvas, present_methods)

Hook so this context can be picked up by canvas.get_context()