new_image¶
MiniLibX: mlx_new_image
Creates an off-screen image: a block of pixels you can fill quickly and draw to windows in one call.
Parameters¶
| Name | Type | Description |
|---|---|---|
mlx |
Mlx |
The connection from init |
width |
int |
Width in pixels, at least 1 |
height |
int |
Height in pixels, at least 1 |
Returns¶
An Image. Every pixel starts as opaque black (all bytes
0).
Raises¶
| Exception | When |
|---|---|
ValueError |
width or height is 0: image size must be at least 1x1 |
OverflowError |
width or height is negative |
Notes¶
- An image isn't tied to a window. You can draw it to any window, as many times as you like.
- Get its pixels with
get_data_addr, and draw it withput_image_to_window. - Python frees the image when nothing refers to it any more.
destroy_imagefrees it straight away.
Example¶
W, H = 640, 480
bg = malibx.new_image(mlx, W, H)
buf, _, _, _ = malibx.get_data_addr(bg)
buf[:] = (0x202830).to_bytes(4, "little") * (W * H) # fill with dark blue-gray
malibx.put_image_to_window(mlx, win, bg, 0, 0)