@@ -67,6 +67,8 @@ interface ErrorCallback {
67
67
}
68
68
69
69
public class Camera {
70
+ private static final String TAG = "Camera" ;
71
+
70
72
private final SurfaceTextureEntry flutterTexture ;
71
73
private final CameraManager cameraManager ;
72
74
private final OrientationEventListener orientationEventListener ;
@@ -99,6 +101,14 @@ public class Camera {
99
101
private boolean useAutoFocus = true ;
100
102
private Range <Integer > fpsRange ;
101
103
104
+ private static final HashMap <String , Integer > supportedImageFormats ;
105
+ // Current supported outputs
106
+ static {
107
+ supportedImageFormats = new HashMap <>();
108
+ supportedImageFormats .put ("yuv420" , 35 );
109
+ supportedImageFormats .put ("jpeg" , 256 );
110
+ }
111
+
102
112
public Camera (
103
113
final Activity activity ,
104
114
final SurfaceTextureEntry flutterTexture ,
@@ -183,15 +193,20 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
183
193
}
184
194
185
195
@ SuppressLint ("MissingPermission" )
186
- public void open () throws CameraAccessException {
196
+ public void open (String imageFormatGroup ) throws CameraAccessException {
187
197
pictureImageReader =
188
198
ImageReader .newInstance (
189
199
captureSize .getWidth (), captureSize .getHeight (), ImageFormat .JPEG , 2 );
190
200
201
+ Integer imageFormat = supportedImageFormats .get (imageFormatGroup );
202
+ if (imageFormat == null ) {
203
+ Log .w (TAG , "The selected imageFormatGroup is not supported by Android. Defaulting to yuv420" );
204
+ imageFormat = ImageFormat .YUV_420_888 ;
205
+ }
206
+
191
207
// Used to steam image byte data to dart side.
192
208
imageStreamReader =
193
- ImageReader .newInstance (
194
- previewSize .getWidth (), previewSize .getHeight (), ImageFormat .YUV_420_888 , 2 );
209
+ ImageReader .newInstance (previewSize .getWidth (), previewSize .getHeight (), imageFormat , 2 );
195
210
196
211
cameraManager .openCamera (
197
212
cameraName ,
0 commit comments