Capture a video frame `to` a canvas element. Optionally scale to `width` and `height`. If no canvas is provided, this will create one. The to parameter can be a canvas Element, raw DOM canvas, or CSS selector string.
(self, to=None, width=None, height=None)
| 1226 | """ |
| 1227 | |
| 1228 | def snap(self, to=None, width=None, height=None): |
| 1229 | """ |
| 1230 | Capture a video frame `to` a canvas element. Optionally scale to |
| 1231 | `width` and `height`. |
| 1232 | |
| 1233 | If no canvas is provided, this will create one. The to parameter |
| 1234 | can be a canvas Element, raw DOM canvas, or CSS selector string. |
| 1235 | """ |
| 1236 | width = width if width else self.videoWidth |
| 1237 | height = height if height else self.videoHeight |
| 1238 | if is_none(to): |
| 1239 | to = canvas(width=width, height=height) |
| 1240 | elif isinstance(to, Element): |
| 1241 | if to.tag != "canvas": |
| 1242 | raise TypeError("Element to snap to must be a canvas.") |
| 1243 | elif getattr(to, "tagName", "") == "CANVAS": |
| 1244 | to = canvas(dom_element=to) |
| 1245 | elif isinstance(to, str): |
| 1246 | nodelist = document.querySelectorAll(to) |
| 1247 | if nodelist.length == 0: |
| 1248 | raise TypeError(f"No element with selector {to} to snap to.") |
| 1249 | if nodelist[0].tagName != "CANVAS": |
| 1250 | raise TypeError("Element to snap to must be a canvas.") |
| 1251 | to = canvas(dom_element=nodelist[0]) |
| 1252 | to.draw(self, width, height) |
| 1253 | return to |
| 1254 | |
| 1255 | |
| 1256 | class datalist(ContainerElement, HasOptions): |
no test coverage detected