public QRCodeScanner() { try { QRCodeDecoder = new QRCodeDecoderLibrary.QRDecoder(); } catch (Exception ex) { Program.WriteToLogFile(ex.ToString()); } }
public static OtpKey FromQR(Image img) { var decoder = new QRCodeDecoderLibrary.QRDecoder(); using var bitmap = new Bitmap(img); var data = decoder.ImageDecoder(bitmap); string uri = QRCodeDecoderLibrary.QRDecoder.ByteArrayToStr(data[0]); return(FromString(uri)); }
public static Result QrBarCodeFromPdf(string uploadFolderPath, string fileFullPath) { try { //get images from source2.pdf //string barCodeImgFullPath = GetImages(uploadFolderPath, fileFullPath); string barCodeImgFullPath = @"C:\Users\placo\OneDrive\Documents\GitHub\PDFExcelCSVExportApp\lab.PDFExcelCSVExportApp\lab.PDFExcelCSVExportApp\wwwroot\upload\Bloom-Richard-QrCode.jpg"; string originalFileName = "Bloom-Richard-QrCode.jpg"; string newFileName120x124 = originalFileName.Substring(0, originalFileName.LastIndexOf('.')) + "-120X124" + originalFileName.Substring(originalFileName.LastIndexOf('.'), originalFileName.Length - originalFileName.LastIndexOf('.')); //string barCodeImgFullPath120x124 = ImageHelper.CropImageWithFullPath(uploadFolderPath, string.Empty, originalFileName, newFileName120x124, 0, 0, 120, 124); string barCodeImgFullPath120x124 = @"C:\Users\placo\OneDrive\Documents\GitHub\PDFExcelCSVExportApp\lab.PDFExcelCSVExportApp\lab.PDFExcelCSVExportApp\wwwroot\upload\Bloom-Richard-QrCode-120X124.jpg"; if (!string.IsNullOrEmpty(barCodeImgFullPath120x124)) { //scan the images for barcode bool imageExist = File.Exists(barCodeImgFullPath120x124); if (imageExist) { // create QR Code decoder object QRCodeDecoderLibrary.QRDecoder qRDecoder = new QRCodeDecoderLibrary.QRDecoder(); using (var image = Image.FromFile(Path.Combine(barCodeImgFullPath120x124))) { Bitmap bitmapImage = new Bitmap(image); // call image decoder methos with <code>Bitmap</code> image of QRCode barcode byte[][] dataByteArray = qRDecoder.ImageDecoder(bitmapImage); string qrCodeResult = ByteArrayToStr(dataByteArray[0]); return(Result.Ok(MessageHelper.BarCodeRead, qrCodeResult)); } } return(Result.Fail(MessageHelper.BarCodeReadFail)); } else { return(Result.Fail(MessageHelper.BarCodeReadFail)); } } catch (Exception) { throw; } }
public static Result GetQrBarCodeFromPdf(string fileFullPath, string outputFullPath) { try { //get images from source2.pdf Image qrCodeImg = GetImagesNew(fileFullPath); if (qrCodeImg != null) { // create QR Code decoder object QRCodeDecoderLibrary.QRDecoder qRDecoder = new QRCodeDecoderLibrary.QRDecoder(); using (var image = qrCodeImg) { Bitmap bitmapImage = new Bitmap(image); // call image decoder methos with <code>Bitmap</code> image of QRCode barcode byte[][] dataByteArray = qRDecoder.ImageDecoder(bitmapImage); string qrCodeResult = ByteArrayToStr(dataByteArray[0]); File.WriteAllText(outputFullPath, qrCodeResult); image.Dispose(); return(Result.Ok(MessageHelper.BarCodeRead, qrCodeResult)); } } else { return(Result.Fail(MessageHelper.BarCodeReadFail)); } } catch (Exception) { throw; } }