translateX static method

double translateX({
  1. required double x,
  2. required Size canvasSize,
  3. required Size imageSize,
  4. required InputImageRotation rotation,
  5. required CameraLensDirection cameraLensDirection,
})

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;
  }
}