canvas property
CanvasElement
canvas
Implementation
CanvasElement get canvas {
if (_source is CanvasElement) {
return _source as CanvasElement;
} else if (_source is ImageElement) {
final imageElement = _source as ImageElement;
_canvas = _source = CanvasElement(width: _width, height: _height);
_canvas!.context2D.drawImageScaled(imageElement, 0, 0, _width, _height);
return _canvas!;
} else if (_source is ImageBitmap) {
final image = _source as ImageBitmap;
_canvas = _source = CanvasElement(width: _width, height: _height);
// Note: We need to use js_util.callMethod, because Dart SDK
// does not support ImageBitmap as a CanvasImageSource
js_util.callMethod<void>(_canvas!.context2D, 'drawImage', [
image,
0,
0,
_width,
_height,
]);
return _canvas!;
} else {
throw StateError('RenderTexture is read only.');
}
}