Scan for all barcode types instead of just QR code

This commit is contained in:
Jaex 2018-12-19 23:47:38 +03:00
parent 8267bb9f5b
commit d87b16073b
2 changed files with 13 additions and 9 deletions

View file

@ -103,7 +103,7 @@ private void EncodeText(string text)
ClearQRCode();
int size = Math.Min(pbQRCode.Width, pbQRCode.Height);
pbQRCode.Image = TaskHelpers.QRCodeEncode(text, size);
pbQRCode.Image = TaskHelpers.CreateQRCode(text, size);
}
}
@ -111,11 +111,11 @@ private void DecodeImage(Bitmap bmp)
{
string output = "";
string[] results = TaskHelpers.QRCodeDecode(bmp);
string[] results = TaskHelpers.BarcodeScan(bmp);
if (results != null)
{
output = string.Join(Environment.NewLine + Environment.NewLine, results.Where(x => !string.IsNullOrEmpty(x)));
output = string.Join(Environment.NewLine + Environment.NewLine, results);
}
txtDecodeResult.Text = output;

View file

@ -1701,7 +1701,7 @@ public static void DownloadAppVeyorBuild()
UpdateMessageBox.Start(updateChecker);
}
public static Image QRCodeEncode(string text, int width, int height)
public static Image CreateQRCode(string text, int width, int height)
{
if (CheckQRCodeContent(text))
{
@ -1730,12 +1730,12 @@ public static Image QRCodeEncode(string text, int width, int height)
return null;
}
public static Image QRCodeEncode(string text, int size)
public static Image CreateQRCode(string text, int size)
{
return QRCodeEncode(text, size, size);
return CreateQRCode(text, size, size);
}
public static string[] QRCodeDecode(Bitmap bmp)
public static string[] BarcodeScan(Bitmap bmp, bool scanQRCodeOnly = false)
{
try
{
@ -1745,16 +1745,20 @@ public static string[] QRCodeDecode(Bitmap bmp)
TryInverted = true,
Options = new DecodingOptions
{
PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE },
TryHarder = true
}
};
if (scanQRCodeOnly)
{
barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
}
Result[] results = barcodeReader.DecodeMultiple(bmp);
if (results != null)
{
return results.Where(x => x != null).Select(x => x.Text).ToArray();
return results.Where(x => x != null && !string.IsNullOrEmpty(x.Text)).Select(x => x.Text).ToArray();
}
}
catch (Exception e)