Error get_image_data
Closed this issue · 2 comments
Using get_image_date I got an error.
RuntimeError: No image data, please be sure that sync_image_data
is set to True
Example
from ipycanvas import Canvas
canvas = Canvas(width=200, height=200, sync_image_data=True)
canvas.fill_rect(25, 25, 100, 100)
canvas.clear_rect(45, 45, 60, 60)
canvas.stroke_rect(50, 50, 50, 50)
arr1 = canvas.get_image_data()
best regards Hebi
Did you execute this entire code in a single code cell?
If so, this is expected, please refer to the documentation https://ipycanvas.readthedocs.io/en/latest/retrieve_images.html#get-image-data-as-a-numpy-array
Note that this won’t work if executed in the same Notebook cell. Because the Canvas won’t have drawn anything yet. If you want to put all your code in the same Notebook cell, you need to define a callback function that will be called when the Canvas has image data.
Closing as answered, but please reopen if you think there is another issue
Thanks
I had a different description