setRotation method

  1. @override
Future<void> setRotation(
  1. OutputRotation rotation
)
override

Set the rotation of the output relative to the natural orientation of the device.

E.g. The natural orientation of a phone is typically portrait up.

Implementation

@override
Future<void> setRotation(OutputRotation rotation) {
  verifyAttached();
  final CameraInfo cameraInfo = _controller.device.info;

  late final int imageRotation;
  switch (rotation) {
    case OutputRotation.rotation0:
      imageRotation = cameraInfo.orientation;
      break;
    case OutputRotation.rotation90:
      if (cameraInfo.facing == CameraInfo.cameraFacingFront) {
        imageRotation = (cameraInfo.orientation + 270) % 360;
      } else {
        imageRotation = (cameraInfo.orientation + 90) % 360;
      }
      break;
    case OutputRotation.rotation180:
      imageRotation = (cameraInfo.orientation + 180) % 360;
      break;
    case OutputRotation.rotation270:
      if (cameraInfo.facing == CameraInfo.cameraFacingFront) {
        imageRotation = (cameraInfo.orientation + 90) % 360;
      } else {
        imageRotation = (cameraInfo.orientation + 270) % 360;
      }
      break;
  }

  _controller.cameraParameters.setRotation(imageRotation);
  return _controller.camera.setParameters(_controller.cameraParameters);
}