Browse Source

downgrade to image v3

pull/98/head
Khoren Markosyan 2 years ago
parent
commit
949dc88407
  1. 4
      example/pubspec.lock
  2. 3
      lib/src/ui/reader_widget.dart
  3. 7
      lib/src/ui/writer_widget.dart
  4. 23
      lib/src/utils/image_converter.dart
  5. 2
      pubspec.yaml

4
example/pubspec.lock

@ -259,10 +259,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: image name: image
sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.0.17" version: "3.3.0"
image_picker: image_picker:
dependency: transitive dependency: transitive
description: description:

3
lib/src/ui/reader_widget.dart

@ -234,7 +234,8 @@ class _ReaderWidgetState extends State<ReaderWidget>
cameraDescription, cameraDescription,
widget.resolution, widget.resolution,
enableAudio: false, enableAudio: false,
imageFormatGroup: ImageFormatGroup.yuv420, imageFormatGroup:
isAndroid() ? ImageFormatGroup.yuv420 : ImageFormatGroup.bgra8888,
); );
controller = cameraController; controller = cameraController;
try { try {

7
lib/src/ui/writer_widget.dart

@ -278,10 +278,9 @@ class _WriterWidgetState extends State<WriterWidget>
if (result.isValid && result.data != null) { if (result.isValid && result.data != null) {
try { try {
final imglib.Image img = imglib.Image.fromBytes( final imglib.Image img = imglib.Image.fromBytes(
width: width, width,
height: height, height,
bytes: result.data!.buffer, result.data!,
numChannels: 4,
); );
final Uint8List encodedBytes = Uint8List.fromList( final Uint8List encodedBytes = Uint8List.fromList(
imglib.encodeJpg(img), imglib.encodeJpg(img),

23
lib/src/utils/image_converter.dart

@ -16,7 +16,7 @@ Future<Uint8List> convertImage(CameraImage image) async {
} else if (image.format.group == ImageFormatGroup.bgra8888) { } else if (image.format.group == ImageFormatGroup.bgra8888) {
img = convertBGRA8888(image); img = convertBGRA8888(image);
} }
return img.toUint8List(); return img.getBytes(format: imglib.Format.luminance); //.toUint8List();
} catch (e) { } catch (e) {
debugPrint('>>>>>>>>>>>> ERROR: $e'); debugPrint('>>>>>>>>>>>> ERROR: $e');
} }
@ -25,10 +25,10 @@ Future<Uint8List> convertImage(CameraImage image) async {
imglib.Image convertBGRA8888(CameraImage image) { imglib.Image convertBGRA8888(CameraImage image) {
return imglib.Image.fromBytes( return imglib.Image.fromBytes(
width: image.width, image.width,
height: image.height, image.height,
bytes: image.planes[0].bytes.buffer, image.planes[0].bytes,
// format: imglib.Format.bgra, format: imglib.Format.bgra,
// format: imglib.Format.int8, // format: imglib.Format.int8,
// order: imglib.ChannelOrder.bgra, // order: imglib.ChannelOrder.bgra,
); );
@ -85,10 +85,11 @@ imglib.Image resizeToMaxSize(imglib.Image image, int? maxSize) {
// get the bytes of the image in grayscale format (luminance) like v3 // get the bytes of the image in grayscale format (luminance) like v3
Uint8List grayscaleBytes(imglib.Image image) { Uint8List grayscaleBytes(imglib.Image image) {
final imglib.Image imgRgba8 = image.convert( return image.getBytes(format: imglib.Format.luminance);
format: imglib.Format.uint8, // final imglib.Image imgRgba8 = image.convert(
numChannels: 1, // format: imglib.Format.uint8,
); // Make sure it's an RGBA 32-bit image like v3 // numChannels: 1,
imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance) // ); // Make sure it's an RGBA 32-bit image like v3
return imgRgba8.getBytes(); // imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance)
// return imgRgba8.getBytes();
} }

2
pubspec.yaml

@ -12,7 +12,7 @@ dependencies:
ffi: ^2.0.0 ffi: ^2.0.0
flutter: flutter:
sdk: flutter sdk: flutter
image: ^4.0.0 image: ^3.0.0
image_picker: ^0.8.0 image_picker: ^0.8.0
melos: ^3.0.0 melos: ^3.0.0

Loading…
Cancel
Save