You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/google_mlkit_commons/README.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,19 @@ From bytes:
105
105
final inputImage = InputImage.fromBytes(bytes: bytes, metadata: metadata);
106
106
```
107
107
108
+
from bitmap data:
109
+
110
+
```dart
111
+
final ui.Image image = await recorder.endRecording().toImage(width, height);
112
+
final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
113
+
final InputImage inputImage = InputImage.fromBitmap(
114
+
bitmap: byteData!.buffer.asUint8List(),
115
+
width: width,
116
+
height: height,
117
+
rotation: 0, // optional, defaults to 0, only used on Android
118
+
);
119
+
```
120
+
108
121
If you are using the [Camera plugin](https://pub.dev/packages/camera) make sure to configure your [CameraController](https://pub.dev/documentation/camera/latest/camera/CameraController-class.html) to only use `ImageFormatGroup.nv21` for Android and `ImageFormatGroup.bgra8888` for iOS.
109
122
110
123
Notice that the image rotation is computed in a different way for both iOS and Android. Image rotation is used in Android to convert the `InputImage`[from Dart to Java](https://github.com/flutter-ml/google_ml_kit_flutter/blob/master/packages/google_mlkit_commons/android/src/main/java/com/google_mlkit_commons/InputImageConverter.java), but it is not used in iOS to convert [from Dart to Obj-C](https://github.com/flutter-ml/google_ml_kit_flutter/blob/master/packages/google_mlkit_commons/ios/Classes/MLKVisionImage%2BFlutterPlugin.m). However, image rotation and `camera.lensDirection` can be used in both platforms to [compensate x and y coordinates on a canvas](https://github.com/flutter-ml/google_ml_kit_flutter/blob/master/packages/example/lib/vision_detector_views/painters/coordinates_translator.dart).
0 commit comments