How to enable Gallery Scan
The SDK allows you to decode barcodes from image files. It supports several image formats, including BMP, PNG, and JPG.
To utilize this feature, you must provide a base64 encoded string as input:
_barkoder.scanImage((result) {
// use the result
}, base64Image);
If you want to use a photo picker to choose an image and decode it, we implement it on our example app, which you can find together with the plugin in the folder example.
We recommend using rigorous speed when decoding an image:
_barkoder.setDecodingSpeed(DecodingSpeed.rigorous);
Steps to Integrate an Image Picker into Your Application:
1. Add the image_picker #
Add package version ^0.8.4+4, to your pubspec.yaml file:
image_picker: ^0.8.4+4
2. Import the image_picker package #
Into your main.dart file import the package:
import 'package:image_picker/image_picker.dart';
3. Setup _scanImage#
Then setup a _scanImage method that will invoke the image picker and then convert that to base64 and send it to our decoder:
void _scanImage() async {
final ImagePicker _picker = ImagePicker();
final XFile? pickedFile =
await _picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
// Read the file and convert it to base64
final bytes = await pickedFile.readAsBytes();
String base64Image = base64Encode(bytes);
// Call scanImage with the base64 string and the callback
_barkoder.scanImage((result) {
_updateState(result, false);
}, base64Image);
}
_updateState(null, !_isScanningActive);
}
4. Best settings#
It is important to note that the settings that we use in this mode, which should result in best decoding results are listed below. Note that this is an all-in setting, so if you are sure you don't want to scan some symbologies, or you don't need to scan deformed images you could change this object:
"gallery_scan": {
"decoder": {
"Aztec": {
"enabled": true
},
"Aztec Compact": {
"enabled": true
},
"QR": {
"enabled": true
},
"QR Micro": {
"enabled": true
},
"Code 128": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0
},
"Code 93": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0
},
"Code 39": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0,
"checksum": 0
},
"Codabar": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0
},
"Code 11": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0,
"checksum": 0
},
"MSI": {
"enabled": true,
"minimumLength": 4,
"maximumLength": 0,
"checksum": 1
},
"Upc-A": {
"enabled": true
},
"Upc-E": {
"enabled": true
},
"Upc-E1": {
"enabled": false
},
"Ean-13": {
"enabled": true
},
"Ean-8": {
"enabled": true
},
"PDF 417": {
"enabled": true
},
"PDF 417 Micro": {
"enabled": true
},
"Datamatrix": {
"enabled": true,
"dpmMode": 1
},
"Code 25": {
"enabled": true,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"Interleaved 2 of 5": {
"enabled": true,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"ITF 14": {
"enabled": true
},
"IATA 25": {
"enabled": true,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"Matrix 25": {
"enabled": true,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"Datalogic 25": {
"enabled": false,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"COOP 25": {
"enabled": true,
"checksum": 0,
"minimumLength": 0,
"maximumLength": 0
},
"Code 32": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0
},
"Telepen": {
"enabled": true,
"minimumLength": 0,
"maximumLength": 0
},
"Dotcode": {
"enabled": true
},
"ID Document": {
"enabled": true
},
"general": {
"maxThreads": 2,
"decodingSpeed": 3,
"roi_x": 0,
"roi_y": 0,
"roi_w": 100,
"roi_h": 100,
"formattingType": 1,
"encodingCharacterSet": "",
"enableMisshaped1D": true,
"upcEanDeblur": true,
"enableVINRestrictions": false
}
},
"closeSessionOnResultEnabled": true,
"barkoderResolution": 0,
"beepOnSuccessEnabled": true,
"vibrateOnSuccessEnabled": false,
"locationInImageResultEnabled": true,
"locationLineWidth": 7
}