Hello, I'm trying to encode data matrix format.
try {
var dataMatrixWriter = MultiFormatWriter();
var encode = dataMatrixWriter.encode(
'FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7',
BarcodeFormat.DATA_MATRIX,
48,
48, {EncodeHintType.DATA_MATRIX_SHAPE : SymbolShapeHint.FORCE_SQUARE, EncodeHintType.MIN_SIZE: Dimension(48,48)});
var scale = 15;
var image = img.Image((encode.width + 2) * scale, (encode.height + 2) * scale);
img.fill(image, Colors.white.value);
for (var x = 0; x < encode.width; x++) {
for (var y = 0; y < encode.height; y++) {
if (encode.get(x, y)) {
img.fillRect(image, (x + 1) * scale, (y + 1) * scale, (x + 1) * scale + scale,
(y + 1) * scale + scale, Colors.black.value);
}
}
}
var pngBytes = img.encodePng(image);
final File generatedImg = MemoryFileSystem().file('test_' + getRandomString(15));
generatedImg.writeAsBytesSync(pngBytes);
setState(() {
_generatedImg = generatedImg;
});
} catch (e, s) {
print(s);
print(e);
}
There are two errors:
- The borders of the matrix are not correct, see:
The first pixel must be black, the 2nd one white, the 3rd black, etc...
Same thing for the second module, it starts with white instead of black.
- I cannot encode with a size more than 48x48 (example 52x52):
try {
var encode = dataMatrixWriter.encode(
'FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7FR03AV011E7F1E7',
BarcodeFormat.DATA_MATRIX,
52,
52, {EncodeHintType.DATA_MATRIX_SHAPE : SymbolShapeHint.FORCE_SQUARE, EncodeHintType.MIN_SIZE: Dimension(52,52)});
} catch (e, s) {
print(s);
print(e);
}
I/flutter ( 6641): #0 _StringBase.substring (dart:core-patch/string_patch.dart:399:7)
I/flutter ( 6641): #1 StringBuilder.replace (package:zxing_lib/src/common/string_builder.dart:39:39)
I/flutter ( 6641): #2 StringBuilder.setCharAt (package:zxing_lib/src/common/string_builder.dart:28:5)
I/flutter ( 6641): #3 ErrorCorrection.encodeECC200 (package:zxing_lib/src/datamatrix/encoder/error_correction.dart:119:14)
I/flutter ( 6641): #4 DataMatrixWriter.encode (package:zxing_lib/src/datamatrix/data_matrix_writer.dart:84:40)
I/flutter ( 6641): #5 MultiFormatWriter.encode (package:zxing_lib/src/multi_format_writer.dart:87:19)
I/flutter ( 6641): #6 _FullScreenCertState.initState.<anonymous closure> (package:pass_sanitaire/main.dart:650:39)
I/flutter ( 6641): #7 _FullScreenCertState.initState.<anonymous closure> (package:pass_sanitaire/main.dart:647:34)
I/flutter ( 6641): #8 _rootRunUnary (dart:async/zone.dart:1436:47)
I/flutter ( 6641): #9 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
I/flutter ( 6641): <asynchronous suspension>
I/flutter ( 6641): RangeError: Value not in range: 206