CanvasImageViewer constructor
CanvasImageViewer({
- CanvasElement? canvas,
- int? width,
- int? height,
- int? maxWidth,
- int? maxHeight,
- bool canvasSizeSameOfRenderedImageSize = true,
- CanvasImageSource? image,
- ImageFilter? imageFilter,
- ViewerElement<
Rectangle< ? clip,num> > - ViewerElement<
List< ? rectangles,Rectangle< >num> > - ViewerElement<
List< ? points,Point< >num> > - ViewerElement<
List< ? labels,Label< >num> > - ViewerElement<
List< ? perspective,Point< >num> > - ViewerElement<
num> ? gridSize, - bool? cropPerspective,
- DateTime? time,
- EditionType? editable,
Implementation
CanvasImageViewer(
{CanvasElement? canvas,
int? width,
int? height,
int? maxWidth,
int? maxHeight,
this.canvasSizeSameOfRenderedImageSize = true,
CanvasImageSource? image,
ImageFilter? imageFilter,
ViewerElement<Rectangle<num>>? clip,
ViewerElement<List<Rectangle<num>>>? rectangles,
ViewerElement<List<Point<num>>>? points,
ViewerElement<List<Label<num>>>? labels,
ViewerElement<List<Point<num>>>? perspective,
ViewerElement<num>? gridSize,
bool? cropPerspective,
this.time,
EditionType? editable})
: _clip = clip,
_rectangles = rectangles,
_points = points,
_labels = labels,
_perspective = perspective,
_gridSize = gridSize,
_editionType = editable,
_maxWidth = isPositiveNumber(maxWidth) ? maxWidth : null,
_maxHeight = isPositiveNumber(maxHeight) ? maxHeight : null,
_imageFilter = imageFilter {
if (_imageFilter != null) {
var imgW = 100;
var imgH = 100;
var wh = getImageDimension(image!);
if (wh != null) {
imgW = wh.width;
imgH = wh.height;
}
image = _imageFilter(image, imgW, imgH);
}
_image = image;
var w = width;
var h = height;
if (w == null || h == null) {
var wh = getImageDimension(_image!);
if (wh != null) {
w ??= wh.width;
h ??= wh.height;
}
}
w ??= 100;
h ??= 100;
if (_image is ImageElement) {
var img = _image;
img.onLoad.listen((_) => _onLoadImage());
}
_renderedImageWidth = _width = w;
_renderedImageHeight = _height = h;
_canvas = canvas ?? CanvasElement(width: w, height: h);
_imagePerspectiveFilterCache = ImagePerspectiveFilterCache(_image!, w, h);
_setCanvasSizeSameOfRenderedImageSize(w, h);
if (isEditable) {
_canvas.onMouseDown.listen(_onMouseDown);
_canvas.onMouseUp.listen(_onMouseUp);
_canvas.onClick.listen(_onMouseClick);
_canvas.onMouseLeave.listen(_onMouseLeave);
_canvas.onMouseMove.listen(_onMouseMove);
} else if (_labels != null && _labels.isNotEmpty) {
_canvas.onMouseMove.listen(_onMouseMove);
}
cropPerspective ??= !isEditable || editable != EditionType.perspective;
_cropPerspective = cropPerspective;
}