jupyter-widgets-contrib/ipycanvas

get_image_data fails

asteppke opened this issue · 1 comments

When trying the example from the documentation to obtain the image data:

from ipycanvas import Canvas

canvas = Canvas(width=200, height=200, sync_image_data=True)
arr1 = canvas.get_image_data()

I unfortunately only receive a traceback:

File C:\tools\miniconda3\envs\jupyter\lib\site-packages\ipycanvas\canvas.py:439, in _CanvasBase.get_image_data(self, x, y, width, height)
    430 """Return a NumPy array representing the underlying pixel data for a specified portion of the canvas.
    431 
    432 This will throw an error if there is no ``image_data`` to retrieve, this happens when nothing was drawn yet or
   (...)
    436 are (``x + width``, ``y + height``).
    437 """
    438 if self.image_data is None:
--> 439     raise RuntimeError(
    440         "No image data, please be sure that ``sync_image_data`` is set to True"
    441     )
    443 x = int(x)
    444 y = int(y)

RuntimeError: No image data, please be sure that ``sync_image_data`` is set to True

although when checking manually it looks as if it is enabled: canvas.sync_image_data is True. This occurs with the latest version 0.12.0.
I am not sure if this is related to https://github.com/martinRenou/ipycanvas/issues/272 but here we cannot even read the data.

My bad, I overlooked the note in the documentation that this needs to be run in separate notebook cells.