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
description:
name: image
sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf
sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6"
url: "https://pub.dev"
source: hosted
version: "4.0.17"
version: "3.3.0"
image_picker:
dependency: transitive
description:

3
lib/src/ui/reader_widget.dart

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

7
lib/src/ui/writer_widget.dart

@ -278,10 +278,9 @@ class _WriterWidgetState extends State<WriterWidget>
if (result.isValid && result.data != null) {
try {
final imglib.Image img = imglib.Image.fromBytes(
width: width,
height: height,
bytes: result.data!.buffer,
numChannels: 4,
width,
height,
result.data!,
);
final Uint8List encodedBytes = Uint8List.fromList(
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) {
img = convertBGRA8888(image);
}
return img.toUint8List();
return img.getBytes(format: imglib.Format.luminance); //.toUint8List();
} catch (e) {
debugPrint('>>>>>>>>>>>> ERROR: $e');
}
@ -25,10 +25,10 @@ Future<Uint8List> convertImage(CameraImage image) async {
imglib.Image convertBGRA8888(CameraImage image) {
return imglib.Image.fromBytes(
width: image.width,
height: image.height,
bytes: image.planes[0].bytes.buffer,
// format: imglib.Format.bgra,
image.width,
image.height,
image.planes[0].bytes,
format: imglib.Format.bgra,
// format: imglib.Format.int8,
// 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
Uint8List grayscaleBytes(imglib.Image image) {
final imglib.Image imgRgba8 = image.convert(
format: imglib.Format.uint8,
numChannels: 1,
); // Make sure it's an RGBA 32-bit image like v3
imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance)
return imgRgba8.getBytes();
return image.getBytes(format: imglib.Format.luminance);
// final imglib.Image imgRgba8 = image.convert(
// format: imglib.Format.uint8,
// numChannels: 1,
// ); // Make sure it's an RGBA 32-bit image like v3
// imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance)
// return imgRgba8.getBytes();
}

2
pubspec.yaml

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

Loading…
Cancel
Save