getImageDimension function

Rectangle<int>? getImageDimension(
  1. CanvasImageSource image
)

Gets the width and height from image (CanvasImageSource).

Implementation

Rectangle<int>? getImageDimension(CanvasImageSource image) {
  if (image is ImageElement) {
    return Rectangle(0, 0, image.naturalWidth, image.naturalHeight);
  } else if (image is CanvasElement) {
    return Rectangle(0, 0, image.width!, image.height!);
  } else if (image is VideoElement) {
    return Rectangle(0, 0, image.width, image.height);
  }
  return null;
}