juliuscanute / qr_code_scanner

QR Code Scanner for Flutter
BSD 2-Clause "Simplified" License
999 stars 759 forks source link

Can't convert raw bytes to an image #599

Open ISL270 opened 2 years ago

ISL270 commented 2 years ago

I've tried many ways to convert Barcode.rawBytes to an image but non of them worked, it always throw the following error: Exception: Invalid image data

Flutter information

[√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.22622.601], locale en-US)
    • Flutter version 3.3.2 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e3c29ec00c (12 days ago), 2022-09-14 08:46:55 -0500
    • Engine revision a4ff2c53d8
    • Dart version 2.18.1
    • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\MM\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] VS Code (version 1.69.2)
    • VS Code at C:\Users\MM\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.48.0

[√] Connected device (1 available)
    • CPH1969 (mobile) • 65GA7545U8C6OV9D • android-arm64 • Android 11 (API 30)

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
brandsimon commented 1 year ago

I can confirm this issue. Raw Bytes is wrong.

brandsimon commented 1 year ago

@ISL270 The rawBytes is in a format, where at the beginning is some info (including the length) and at the end is probably garbage. I wrote a function[0] to convert it to the real rawBytes. I recommend you to use mobile_scanner, I only need this because f-droid does not allow mlkit. If you also cant switch, please let me know, if it works for you.

[0] https://gitlab.com/cryptographic_id/cryptographic-id-flutter/-/commit/a0892c6897be9000d3557f5eef547adcd6f14689#932d7902fc30f7cb185006c09df76f3830fa0afb_0_5