https://github.com/Redth/ZXing.Net.Mobile
https://components.xamarin.com/view/zxing.net.mobile
[TestMethod]
public void SimpleQrCode()
{
IBarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
ErrorCorrection = ErrorCorrectionLevel.L,
Height = 500,
Width = 500,
Margin = 10
}
};
var result = writer.Write("test content");
var barcodeBitmap = new Bitmap(result);
barcodeBitmap.Save("C:\\Temp\\qrCode.png", ImageFormat.Png);
Assert.IsTrue(File.Exists("C:\\Temp\\qrCode.png"));
}
[TestMethod]
public void SimpleQrCode()
{
var options = new QrCodeEncodingOptions
{
ErrorCorrection = ErrorCorrectionLevel.H, //this allowed me to place my image in the centre of the QR code and maintained scanning functionality.
Height = 500,
Width = 500,
Margin = 0
};
IBarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = options
};
var result = writer.Write("test content");
var barcodeBitmap = new Bitmap(result);
barcodeBitmap.Save(string.Format("C:\\Temp\\qrCode{0}x{1}.png", options.Width, options.Height), ImageFormat.Png);
Assert.IsTrue(File.Exists(string.Format("C:\\Temp\\qrCode{0}x{1}.png", options.Width, options.Height)));
}
public void handleDecode(final Result rawResult, Bitmap barcode, float scaleFactor) {
inactivityTimer.onActivity();
lastResult = rawResult;
try{
// your code here
restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
}
catch(Exception e){
}
}
Hope this helpsThe standard encoding for QR code is ISO8859-1 (defined in the specs).
Your characters are not valid for that character set.
If you want to use such content in a correct way you have to define the UTF-8 character set in the encoding options:
```
var _barkodYazici = new ZXing.BarcodeWriter()
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new ZXing.QrCode.QrCodeEncodingOptions()
{
Height = 300,
Width = 300,
Margin = 1,
CharacterSet = "UTF-8"
}
};
```
The encoder automatically adds the necessary ECI segment. Some readers have trouble with the ECI segment, so you can explicitly disable it with another option.
```
var _barkodYazici = new ZXing.BarcodeWriter()
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new ZXing.QrCode.QrCodeEncodingOptions()
{
Height = 300,
Width = 300,
Margin = 1,
CharacterSet = "UTF-8",
DisableECI = true
}
};
```
await _mediaCapture.StartPreviewAsync();
int i = 0;
var barcodeReader = new BarcodeReader
{
TryHarder = true,
AutoRotate = true
};
while (_result == null)
{
photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.ReplaceExisting);
await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
var stream = await photoStorageFile.OpenReadAsync();
var writeableBmp = new WriteableBitmap(1, 1);
writeableBmp.SetSource(stream);
writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
stream.Seek(0);
writeableBmp.SetSource(stream);
_result = barcodeReader.Decode(writeableBmp);
if (_result != null)
{
CaptureImage.Source = writeableBmp;
}
i += 1;
ScanResult.Text = "Nummer " + i;
}
await _mediaCapture.StopPreviewAsync();
VideoCapture.Visibility = Visibility.Collapsed;
CaptureImage.Visibility = Visibility.Visible;
ScanResult.Text = _result.Text;
}