public void GetImage() { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Open Image"; dlg.Filter = "PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg"; if (dlg.ShowDialog() == true) { var uri = new Uri(dlg.FileName); // Resizes image, due to performance concerns Image = BitmapResizer.Scaler(new BitmapImage(uri), 500, 500); } }
public async Task <IActionResult> DecodeQrCode(IFormFile qrCodeInput, string returnUrl) { if (!qrCodeInput.IsImage()) { return(await QrCodeError(returnUrl)); } var vm = new ValidatePersonModel() { ReturnUrl = returnUrl }; using (var bitmap = new System.Drawing.Bitmap(qrCodeInput.OpenReadStream())) { var image = BitmapResizer.Resize(bitmap, 600, 800); var reader = new ZXing.ImageSharp.BarcodeReader <Rgba32> { Options = { PossibleFormats = new List <BarcodeFormat> { BarcodeFormat.QR_CODE } } }; var result = reader.Decode(image); if (result == null) { _logger.LogError("QR Code is invalid"); return(await QrCodeError(returnUrl)); } var user = _userManager.FindByCodeAsync(result.Text); if (user == null) { _logger.LogError("No user found for QR Code"); return(await QrCodeError(returnUrl)); } vm.User = user; } return(View("ValidatePerson", vm)); }