rotateCanvasImageSource function
CanvasElement
rotateCanvasImageSource(
- CanvasImageSource image,
- int width,
- int height, [
- dynamic angleDegree = 90,
Rotates image
(a CanvasImageSource) with angleDegree
.
width
Width of the image.
height
Height of the image.
Implementation
CanvasElement rotateCanvasImageSource(
CanvasImageSource image, int width, int height,
[angleDegree = 90]) {
angleDegree ??= 90;
var canvas = CanvasElement(width: height, height: width);
var context = canvas.getContext('2d') as CanvasRenderingContext2D;
context.translate(canvas.width! / 2, canvas.height! / 2);
context.rotate(angleDegree * math.pi / 180);
context.drawImage(image, -width / 2, -height / 2);
return canvas;
}