Skip to content

Commit 1a6b6f0

Browse files
committed
Add create_image_data method
1 parent 992a432 commit 1a6b6f0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ipycanvas/canvas.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from contextlib import contextmanager
88

9+
import numpy as np
10+
911
from traitlets import Enum, Float, Instance, List, Tuple, Unicode, observe
1012

1113
from ipywidgets import Color, DOMWidget, widget_serialization
@@ -224,6 +226,10 @@ def put_image_data(self, image_data, dx, dy):
224226
shape, image_buffer = array_to_binary(image_data)
225227
self._send_canvas_command('putImageData', ({'shape': shape}, dx, dy), (image_buffer, ))
226228

229+
def create_image_data(self, width, height):
230+
"""Create a NumPy array of shape (width, height, 4) representing a table of pixel colors."""
231+
return np.zeros((width, height, 4), dtype=int)
232+
227233
# Clipping
228234
def clip(self):
229235
"""Turn the path currently being built into the current clipping path.

0 commit comments

Comments
 (0)