inputImageFromBytes method

  1. @visibleForTesting
InputImage? inputImageFromBytes(
  1. Uint8List bytes,
  2. int width,
  3. int height,
  4. int bytesPerRow,
)

Implementation

@visibleForTesting
InputImage? inputImageFromBytes(
  Uint8List bytes,
  int width,
  int height,
  int bytesPerRow,
) {
  if (_cameraController == null || _availableCameras.isEmpty) return null;
  final camera = _availableCameras[_selectedCameraIndex];
  final sensorOrientation = camera.sensorOrientation;
  final rotation = InputImageRotationValue.fromRawValue(sensorOrientation);
  if (rotation == null) return null;

  final format = defaultTargetPlatform == TargetPlatform.android
      ? InputImageFormat.nv21
      : InputImageFormat.bgra8888;

  return InputImage.fromBytes(
    bytes: bytes,
    metadata: InputImageMetadata(
      size: Size(width.toDouble(), height.toDouble()),
      rotation: rotation,
      format: format,
      bytesPerRow: bytesPerRow,
    ),
  );
}