(bugfix) decoding hub3a from image did not work
This commit is contained in:
@@ -309,8 +309,21 @@ const decodeFromCanvas = async (canvas:HTMLCanvasElement): Promise<Array<DecodeR
|
||||
}
|
||||
|
||||
/** Finds PDF417 code within a base64 encoded image and decodes it */
|
||||
export const decodeFromImage = async (imageBase64:string): Promise<DecodeResult[]|null> => {
|
||||
return(await decodeFromCanvas( await image2canvas(imageBase64) ));
|
||||
export const decodeFromImage = async (imageBase64:string): Promise<DecodeResult|null> => {
|
||||
const canvas = await image2canvas(imageBase64);
|
||||
|
||||
const hints = new Map();
|
||||
hints.set(DecodeHintType.POSSIBLE_FORMATS, [ BarcodeFormat.PDF_417 ]);
|
||||
hints.set(DecodeHintType.PURE_BARCODE, false);
|
||||
|
||||
const codeReader = new BrowserPDF417Reader(hints);
|
||||
const result = await codeReader.decodeFromCanvas(canvas);
|
||||
const hub3aText = result.getText();
|
||||
|
||||
return({
|
||||
hub3aText,
|
||||
billInfo: parseHubText(hub3aText)
|
||||
});
|
||||
}
|
||||
|
||||
/** Finds PDF417 code within a file and decodes it */
|
||||
|
||||
@@ -53,10 +53,10 @@ export const BillEditForm: FC<BillEditFormProps> = ({ location, bill }) => {
|
||||
// by converting it to `hub3aText`
|
||||
if (!hub3aText && bill?.barcodeImage) {
|
||||
decodeFromImage(bill.barcodeImage).then(results => {
|
||||
if (results && results.length > 0) {
|
||||
if (results) {
|
||||
const {
|
||||
hub3aText: decodedHub3aText,
|
||||
} = results[0];
|
||||
} = results;
|
||||
|
||||
setHub3aText(decodedHub3aText);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user