-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Steps to reproduce
I previously filed this as #138933 but got sidetracked and it got locked - sorry.
When using camera_android_camerax the ResolutionPreset values are no longer correct - and in my test case was much lower (and unusable - my barcode recognition was no longer able to recognise any barcodes). It additionally seems to use a lot more resources, when I used a higher setting to try and match the original resolution the app was more laggy.
I have reproduced this on multiple devices now on some the camera is at least USABLE, on others the resolution ends up being so poor I can't use it.
Expected results
Resolution of Camera output should match the values for ResolutionPreset
enum ResolutionPreset {
/// 352x288 on iOS, 240p (320x240) on Android and Web
low,
/// 480p (640x480 on iOS, 720x480 on Android and Web)
medium,
/// 720p (1280x720)
high,
/// 1080p (1920x1080)
veryHigh,
/// 2160p (3840x2160 on Android and iOS, 4096x2160 on Web)
ultraHigh,
/// The highest resolution available.
max,
}
When using ResolutionPreset.High WITHOUT cameraX, resolution is 1280x720.

Actual results
When using ResolutionPreset.High WITH cameraX resolution is much lower!

Code sample
Pubspec.yaml
camera: ^0.10.5+5
camera_android_camerax: ^0.5.0+22
Main.dart
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
late List<CameraDescription> _cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
_cameras = await availableCameras();
runApp(const CameraApp());
}
/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
/// Default Constructor
const CameraApp({super.key});
@override
State<CameraApp> createState() => _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
late CameraController controller;
@override
void initState() {
super.initState();
controller = CameraController(_cameras[0], ResolutionPreset.high);
controller.initialize().then((_) {
controller.startImageStream(_processCameraImage);
if (!mounted) {
return;
}
setState(() {});
}).catchError((Object e) {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
// Handle access errors here.
break;
default:
// Handle other errors here.
break;
}
}
});
}
Future _processCameraImage(CameraImage image) async {
final WriteBuffer allBytes = WriteBuffer();
for (final Plane plane in image.planes) {
allBytes.putUint8List(plane.bytes);
}
final bytes = allBytes.done().buffer.asUint8List();
final Size imageSize = Size(image.width.toDouble(), image.height.toDouble());
print("size: ${imageSize.width} / ${imageSize.height}");
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return Container();
}
return MaterialApp(
home: CameraPreview(controller),
);
}
}
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.0, on macOS 14.2.1 23C71 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[!] Android Studio (version unknown)
✗ Unable to determine Android Studio version. [I have 2 versions installed on MacOS]
[✓] Android Studio (version 2023.1)
[✓] Connected device (3 available)
[✓] Network resources
Metadata
Metadata
Assignees
Labels
Type
Projects
Status