You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/basic_usage.rst
-31Lines changed: 0 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,37 +48,6 @@ The ``Canvas`` and ``MultiCanvas`` classes have a ``clear`` method which allows
48
48
49
49
canvas.clear()
50
50
51
-
Save Canvas to a file
52
-
---------------------
53
-
54
-
You can dump the current ``Canvas`` or ``MultiCanvas`` image using the ``to_file`` method. You first need to specify that you want the image data to be synchronized between the front-end and the back-end setting the ``sync_image_data`` attribute to ``True``.
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 is ready to be dumped to an image file.
There are two methods for retrieving the canvas image:
5
+
6
+
- ``to_file(filename)``: Dumps the image data to a PNG file.
7
+
- ``get_image_data(x=0, y=0, width=None, height=None)``: Get the image data as a NumPy array for a sub-portion of the Canvas.
8
+
9
+
By default, and in order to keep ipycanvas fast, the image state of the Canvas is not synchronized between the TypeScript front-end and the Python back-end. If you want to retrieve the image data from the Canvas, you first need to explicitly specify that you want the image to be synchronized by setting ``sync_image_data`` to ``True`` before doing any drawing, you can set ``sync_image_data`` back to ``False`` once you're done.
10
+
11
+
Save Canvas to a file
12
+
---------------------
13
+
14
+
You can dump the current ``Canvas`` or ``MultiCanvas`` image to a PNG file using the ``to_file`` method.
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 is ready to be dumped to an image file.
arr1 = canvas.get_image_data() # Get the entire Canvas as a NumPy array
56
+
arr2 = canvas.get_image_data(50, 10, 40, 60) # Get the subpart defined by the rectangle at position (x=50, y=10) and of size (width=40, height=60)
57
+
58
+
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.
0 commit comments