private void ReadBitmap(Bitmap bitmap)
{
var reader = new ZXing.BarcodeReader();
reader.Options.TryHarder = true;
reader.AutoRotate = true;
var decoded = reader.Decode(bitmap);
if (decoded != null)
{
var text = decoded.Text;
var uri = new Uri(text);
if (uri.Scheme == "otpauth")
{
var queryString = HttpUtility.ParseQueryString(uri.Query);
var secret = queryString["secret"];
var account = uri.LocalPath.StartsWith("/") ? uri.LocalPath.Substring(1) : uri.LocalPath;
txtAccountName.Text = HttpUtility.UrlDecode(account);
Key = secret;
}
else
{
MessageBox.Show("The QR Code does not contain valid OAuth data", "Authentiqr.NET", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("The QR Code could not be read", "Authentiqr.NET", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}