translateX static method
Translates the X coordinate based on canvas and image size, rotation, and camera lens direction.
x
The X coordinate to be translated.
canvasSize
The size of the canvas where the image is displayed.
imageSize
The size of the original image.
rotation
The rotation of the input image.
cameraLensDirection
The direction of the camera lens (front or back).
Returns the translated X coordinate.
Implementation
static double translateX({
required double x,
required Size canvasSize,
required Size imageSize,
required InputImageRotation rotation,
required CameraLensDirection cameraLensDirection,
}) {
double imageWidth = Platform.isIOS ? imageSize.width : imageSize.height;
switch (rotation) {
case InputImageRotation.rotation90deg:
return x * canvasSize.width / imageWidth;
case InputImageRotation.rotation270deg:
return canvasSize.width - x * canvasSize.width / imageWidth;
case InputImageRotation.rotation0deg:
case InputImageRotation.rotation180deg:
double translatedX = x * canvasSize.width / imageSize.width;
return cameraLensDirection == CameraLensDirection.front
? canvasSize.width - translatedX
: translatedX;
}
}