public QRDecoder(BinaryBitmap xBitmap) { QRCodeReader xReader = new QRCodeReader(); // m_xResult = xReader.decode(xBitmap); }
private Result ProcessQRReader(Bitmap image) { image = preProcessImage(image); //image = new Bitmap("d:\\AMA_QR.bmp"); LuminanceSource ls = new RGBLuminanceSource(image, image.Width, image.Height); Binarizer hb = new HybridBinarizer(ls); Result result = null; BinaryBitmap bbitmap = new BinaryBitmap(hb); try { result = reader.decode(bbitmap); } catch (ReaderException rex) { Console.WriteLine(rex.Message); if (counter == 0) { image = paddingImage(image, 20); counter = 1; return(ProcessQRReader(image)); } else { counter = 0; } } catch (Exception ex) { Console.WriteLine(ex.Message); } counter = 0; return(result); }
public void ReadQRCode(Color[] clist, int width, int height, Action <string> OnOk = null) { byte[] bcolor = new byte[width * height * 3]; for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { bcolor[offset * 3 + x * 3] = (byte)(clist[x * height + y].r * 255); bcolor[offset * 3 + x * 3 + 1] = (byte)(clist[x * height + y].g * 255); bcolor[offset * 3 + x * 3 + 2] = (byte)(clist[x * height + y].b * 255); } } Loom.RunAsync(() => { try { QRCodeReader qrreader = new QRCodeReader(); RGBLuminanceSource scource = new RGBLuminanceSource(bcolor, width, height); HybridBinarizer binarizer = new HybridBinarizer(scource); BinaryBitmap bitmap = new BinaryBitmap(binarizer); Result result = qrreader.decode(bitmap); Loom.QueueOnMainThread(() => { OnOk(result.Text); }); } catch (Exception ex) { } }); }
/// <summary> /// Escanea el buffer de la cámara y si /// detectó un código QR lo manda a la vista ImagePicker /// </summary> private void ScanPreviewBuffer() { try { photoCamera.GetPreviewBufferY(luminance.PreviewBufferY); var binarizer = new HybridBinarizer(luminance); var binBitmap = new BinaryBitmap(binarizer); var result = reader.decode(binBitmap); if (result == null) { return; } // Se leyó el código QR this.qrCodeText = result.Text; this.Dispatcher.BeginInvoke(() => { timer.Stop(); photoCamera.Dispose(); NavigationService.Navigate(new Uri(String.Format("/ImagePicker.xaml?qr={0}", qrCodeText), UriKind.Relative)); }); } catch (Exception) { MessageBox.Show("Ocurrió un error al tratar de decodificar el código QR", "Photo Sharing", MessageBoxButton.OK); } }
private bool ScanQRCodeStretch(Screen screen, Bitmap fullImage, Rectangle cropRect, double mul, out string url, out Rectangle rect) { Bitmap target = new Bitmap((int)(cropRect.Width * mul), (int)(cropRect.Height * mul)); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel); } var source = new BitmapLuminanceSource(target); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); if (result != null) { url = result.Text; double minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; foreach (ResultPoint point in result.ResultPoints) { minX = Math.Min(minX, point.X); minY = Math.Min(minY, point.Y); maxX = Math.Max(maxX, point.X); maxY = Math.Max(maxY, point.Y); } //rect = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)); rect = new Rectangle(cropRect.Left + (int)(minX / mul), cropRect.Top + (int)(minY / mul), (int)((maxX - minX) / mul), (int)((maxY - minY) / mul)); return(true); } url = ""; rect = new Rectangle(); return(false); }
private void Scan() { if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null) { try { // 2-2-2012 - Rowdy.nl // Focus the camera for better recognition of QR code's if (_photoCamera.IsFocusSupported) { _photoCamera.Focus(); } // End Rowdy.nl _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY); var binarizer = new HybridBinarizer(_luminanceSource); var binaryBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binaryBitmap, QRCodeHint); StopScanning(); OnResult(result); } catch (ReaderException) { // There was not a successful QR code read in the scan // pass. Invoke and try again soon. Dispatcher.BeginInvoke(Scan); } catch (Exception ex) { OnError(ex); } } }
protected void btnDecode_Click(object sender, EventArgs e) { if (Convert.ToString(Session["isDefaultImage"]) == "IsDefault") { lblErrorDecode.Text = "Upload QR Code First!"; lblErrorDecode.ForeColor = System.Drawing.Color.Red; return; } property.path = Server.MapPath("~/Images/QR_Codes/" + "img.bmp"); System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(File.ReadAllBytes(property.path))); Bitmap bitMap = new Bitmap(image); try { com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitMap, bitMap.Width, bitMap.Height); var binarizer = new com.google.zxing.common.HybridBinarizer(source); var binBitmap = new com.google.zxing.BinaryBitmap(binarizer); QRCodeReader qrCodeReader = new QRCodeReader(); com.google.zxing.Result str = qrCodeReader.decode(binBitmap); txtDecodedOriginalInfo.Text = str.ToString(); lblErrorDecode.Text = "Successfully Decoded!"; lblErrorDecode.ForeColor = System.Drawing.Color.Green; } catch { } }
/// <summary> /// 使用二维码匹配SS服务器信息 /// </summary> /// <param name="url">二维码地址</param> /// <returns>结果的Server对象</returns> protected Server getFreeServerByQrCode(string url) { Server serv = null; HttpGet(url, Convert.ToString(Environment.TickCount), (responseStream) => { using (Bitmap target = new Bitmap(responseStream)) { var source = new BitmapLuminanceSource(target); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); if (result != null) { serv = new Server(result.Text); } else { Logging.Error("Decode QR Code Err"); } } }); return(serv); }
public static string ScanQRCodeFromScreen() { var screenLeft = SystemParameters.VirtualScreenLeft; var screenTop = SystemParameters.VirtualScreenTop; var screenWidth = SystemParameters.VirtualScreenWidth; var screenHeight = SystemParameters.VirtualScreenHeight; using (Bitmap bmp = new Bitmap((int)screenWidth, (int)screenHeight)) { using (Graphics g = Graphics.FromImage(bmp)) g.CopyFromScreen((int)screenLeft, (int)screenTop, 0, 0, bmp.Size); int maxTry = 10; for (int i = 0; i < maxTry; i++) { int marginLeft = (int)((double)bmp.Width * i / 2.5 / maxTry); int marginTop = (int)((double)bmp.Height * i / 2.5 / maxTry); Rectangle cropRect = new Rectangle(marginLeft, marginTop, bmp.Width - marginLeft * 2, bmp.Height - marginTop * 2); Bitmap target = new Bitmap((int)screenWidth, (int)screenHeight); double imageScale = screenWidth / cropRect.Width; using (Graphics g = Graphics.FromImage(target)) g.DrawImage(bmp, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel); var source = new BitmapLuminanceSource(target); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); if (result != null) { return(result.Text); } } } return(""); }
/// <summary> /// »ñÈ¡¶þάÂë×Ö·û´® /// </summary> /// <returns></returns> public string GetQRCodeString() { Bitmap bmap = GetClipboardBitmap(); if (bmap == null) { return(null); } QRCodeReader qrRead = new QRCodeReader(); BitmapLuminanceSource source = new BitmapLuminanceSource(bmap); BinaryBitmap binBitmap = new BinaryBitmap(new HybridBinarizer(source)); string retString = null; try { Result results = qrRead.decode(binBitmap); if (results != null) { retString = DeEncryString(results.Text); } } catch (Exception ex) { return(null); } return(retString); }
private void DoQrToBin(string filename) { try { var fileStream = File.OpenRead(filename); var img = Image.FromStream(fileStream); var bmp = new Bitmap(img); fileStream.Close(); var binary = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height))); var reader = new QRCodeReader(); var result = reader.decode(binary); var resultList = (ArrayList)result.ResultMetadata[ResultMetadataType.BYTE_SEGMENTS]; if (resultList == null) { File.WriteAllBytes(filename + ".txt", Encoding.UTF8.GetBytes(result.Text)); System.Diagnostics.Process.Start(filename + ".txt"); txtQRText.Text = result.Text; } else { File.WriteAllBytes(filename + ".bin", (byte[])resultList[0]); } } catch (ReaderException ex) { MessageBox.Show(@"Error Loading:" + Environment.NewLine + ex.Message); } }
static void barcode_decode(string path) { ImageConverter converter = new ImageConverter(); var reader = new ZXing.QrCode.QRCodeReader(); //ZXing.BinaryBitmap var dest = (Bitmap)Bitmap.FromFile(path); var bb = (byte[])converter.ConvertTo(dest, typeof(byte[])); // ; // BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); var source = new BitmapLuminanceSource(dest); // LuminanceSource source = new RGBLuminanceSource(bb,dest.Width,dest.Height, RGBLuminanceSource.BitmapFormat.RGB32); HybridBinarizer binarizer = new HybridBinarizer(source); BinaryBitmap binBitmap = new BinaryBitmap(binarizer); QRCodeReader qrr = new QRCodeReader(); var result = qrr.decode(binBitmap); if (result != null) { var text = result.Text; Console.WriteLine(text); } else { Console.WriteLine("Err"); } }
private void ScanPreviewBuffer() { if (NavigationService.CurrentSource == new Uri("/ScannerPage.xaml", UriKind.Relative)) { try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); Dispatcher.BeginInvoke(() => DisplayResult(result.Text)); // katsotaan miten käy if (result.Text != null) { string kysymysID; string viesti = result.Text; int categoryIdIndex = viesti.IndexOf("kysymys") + 7; kysymysID = viesti.Substring(categoryIdIndex); Dispatcher.BeginInvoke(() => KysymysSaatu(kysymysID)); } } catch (Exception ex) { //Dispatcher.BeginInvoke(() => NaytaException(ex.Message)); } } }
private void Scan() { if (IsScanning && _initialized && _photoCamera != null && _luminanceSource != null && _reader != null) { try { // 2-2-2012 - Rowdy.nl // Focus the camera for better recognition of QR code's if (_photoCamera.IsFocusSupported) { _photoCamera.Focus(); } // End Rowdy.nl _photoCamera.GetPreviewBufferY(_luminanceSource.PreviewBufferY); var binarizer = new HybridBinarizer(_luminanceSource); var binaryBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binaryBitmap, QRCodeHint); if (result != null) { StopScanning(); OnResult(result); } } catch (ReaderException) { } catch (Exception ex) { OnError(ex); } } }
private void ScanPreviewBuffer() { try { int width = Convert.ToInt32(photoCamera.PreviewResolution.Width); int height = Convert.ToInt32(photoCamera.PreviewResolution.Height); PhotoCameraLuminanceSource _luminance = new PhotoCameraLuminanceSource(width, height); photoCamera.GetPreviewBufferY(_luminance.PreviewBuferY); var binBitmap = new BinaryBitmap(new HybridBinarizer(_luminance)); var result = codeReader.decode(binBitmap); if (result != null) { MessageBox.Show("Codigo Atrapado"); Link.Content = "Abrir Link"; Link.NavigateUri = new Uri("" + result, UriKind.Absolute); Link.TargetName = "_blank"; ContentPanel2.Children.Add(Link); //Link.Click += new RoutedEventHandler(URLink_Click); } } catch { } }
void AddQR(Bitmap bmp) { LuminanceSource source = new RGBLuminanceSource(bmp, bmp.Width, bmp.Height); BinaryBitmap bin = new BinaryBitmap(new HybridBinarizer(source)); Result res = qrReader.decode(bin); StatusL.Text = "QR 読み取り成功"; string ret = res.Text.Sanitize(); foreach (QR QR in QRs) { if (QR.RawShapeData == ret) { StatusL.Text = "QR 読み取り済み"; return; } } QRInputT.Text = ret; QR qr = new QR(ret); QRs.Add(qr); foreach (Shape s in qr.Shapes) { AddShape(s); } if (qr.IsFrameAvailable) { AddShape(qr.Frame, "Frame", Pens.BurlyWood, Brushes.BurlyWood); } }
public static string GetQRCode(Bitmap imageToSearch) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown if (false) { Dictionary <DecodeHintType, object> dictionary = new Dictionary <DecodeHintType, object>(); QRCodeReader val = new QRCodeReader(); BitmapLuminanceSource val2 = new BitmapLuminanceSource(imageToSearch); BinaryBitmap val3 = new BinaryBitmap(new HybridBinarizer(val2)); Result val4 = val.decode(val3); return((val4 != null) ? val4.Text : null); } QRDecoder val5 = new QRDecoder(); byte[][] array = val5.ImageDecoder(imageToSearch); if (array == null) { return(null); } if (array.GetLength(0) > 0) { return(Encoding.UTF8.GetString(array[0])); } return(null); }
//private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e) //{ //} private void timer1_Tick(object sender, EventArgs e) { QRCodeReader Scanner = new QRCodeReader(); if (pictureBox1.Image != null) { byte[] mybyte = (byte[])new ImageConverter().ConvertTo(pictureBox1.Image, Type.GetType("Byte")); LuminanceSource source = new RGBLuminanceSource(mybyte, pictureBox1.Image.Width, pictureBox1.Image.Height); var bin = new HybridBinarizer(source); var binBit = new BinaryBitmap(bin); Result result = Scanner.decode(binBit); try { string decoded = result.ToString().Trim(); if (decoded == "Hello") { MessageBox.Show(decoded); timer1.Stop(); } //splitContainer1.Panel2.Enabled = true; //textBox1.Text = decoded; } catch (Exception ex) { } } }
private void addServerQRCode(object parameter) { Bitmap bitmapScreen = new Bitmap((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bitmapScreen)) { graphics.CopyFromScreen(0, 0, 0, 0, bitmapScreen.Size, CopyPixelOperation.SourceCopy); } var sourceScreen = new BitmapLuminanceSource(bitmapScreen); var bitmap = new BinaryBitmap(new HybridBinarizer(sourceScreen)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); if (result == null || string.IsNullOrWhiteSpace(result.Text)) { App.ShowNotify(sr_config_0_found); return; } List <ServerProfile> serverList = ServerManager.ImportServers(result.Text); if (serverList.Count > 0) { int added = addServer(serverList); App.ShowNotify($"{added} {sr_config_x_imported}"); } else { App.ShowNotify(sr_config_0_imported); } }
static bool ScanWindow(Bitmap screenshot, Point screenLocation, Rectangle winRect, Rectangle screenRect, Action <string> success) { Result result; using (Bitmap window = new Bitmap(winRect.Width, winRect.Height)) { using (Graphics g = Graphics.FromImage(window)) { g.DrawImage(screenshot, winRect, screenRect, GraphicsUnit.Pixel); } var binBMP = new BinaryBitmap( new HybridBinarizer( new BitmapLuminanceSource(window))); QRCodeReader reader = new QRCodeReader(); result = reader.decode(binBMP); } if (result == null) { return(false); } ShowResult(result, screenLocation, winRect, screenRect, success); return(true); }
public static Result ScanBitmap(Bitmap target) { var source = new BitmapLuminanceSource(target); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); var reader = new QRCodeReader(); return(reader.decode(bitmap)); }
/// <summary> /// Try to decode. Throws exception!! /// </summary> /// <returns>ScanResult if successful</returns> public ScanResult Decode() { binarizer = new HybridBinarizer(luminance); binBitmap = new BinaryBitmap(binarizer); Result r = reader.decode(binBitmap, hints); return(new ScanResult(ConvertFormat(r.BarcodeFormat), r.Text)); }
public void CheckUpdate(ShadowsocksController controller, bool use_proxy) { try { QRCodeNodeResult = false; Configuration config = controller.GetConfiguration(); foreach (var item in config.nodeFeedQRCodeURLs) { bool success = false; byte[] qrCodeData = null; qrCodeData = DownloadData(config, item.url, use_proxy); //if (qrCodeData == null) //{ // qrCodeData = DownloadData(config, item.url, !use_proxy); //} if (qrCodeData != null) { //读入MemoryStream对象 MemoryStream memoryStream = new MemoryStream(qrCodeData, 0, qrCodeData.Length); memoryStream.Write(qrCodeData, 0, qrCodeData.Length); //转成图片 Image image = Image.FromStream(memoryStream); Bitmap target = new Bitmap(image); var source = new BitmapLuminanceSource(target); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); if (result != null) { success = AddServerBySSURL(ref config, result.Text, config.nodeFeedQRCodeGroup, true); } } if (success) { item.state = QRCodeUrlState.Normal; } else { item.state = QRCodeUrlState.Exception; } } controller.SaveServersConfig(config); QRCodeNodeResult = true; if (NewQRCodeNodeFound != null) { NewQRCodeNodeFound(this, new EventArgs()); } } catch (Exception ex) { Logging.Debug(ex.ToString()); if (NewQRCodeNodeFound != null) { NewQRCodeNodeFound(this, new EventArgs()); } return; } }
private static T GetQrCodeContent <T>(byte[] data) { var reader = new QRCodeReader(); using var bitmap = new Bitmap(new MemoryStream(data)); var binary = new BinaryBitmap( new HybridBinarizer(new RGBLuminanceSource(data, bitmap.Width, bitmap.Height)) ); return(JsonMapper.Map <T>(reader.decode(binary).Text)); }
public static string ScanScreen() { try { foreach (Screen screen in Screen.AllScreens) { using (Bitmap fullImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height)) { using (Graphics g = Graphics.FromImage(fullImage)) { g.CopyFromScreen(screen.Bounds.X, screen.Bounds.Y, 0, 0, fullImage.Size, CopyPixelOperation.SourceCopy); } int maxTry = 10; for (int i = 0; i < maxTry; i++) { int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry); int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry); Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2); Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height); double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width; using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel); } BitmapLuminanceSource source = new BitmapLuminanceSource(target); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); Result result = reader.decode(bitmap); if (result != null) { string ret = result.Text; return(ret); } } } } } catch { } return(string.Empty); }
public string QRDecode(byte[] bytes) { using (MemoryStream ms = new MemoryStream(bytes)) using (Bitmap bmp = new Bitmap(ms)) { var source = new BitmapLuminanceSource(bmp); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); var result = reader.decode(bitmap); return(result?.Text); } }
public string Decode(SoftwareBitmap image) { var bitmap = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(); image.CopyToBuffer(bitmap.PixelBuffer); var result = qrCodeReader.decode(bitmap); if (result != null) { return result.Text; } return null; }
public List <ScanInfo> ScanImages(string sourcePath) // take every sourcePath and pair it with the QR codes it came with { string[] myPaths = Directory.GetFiles(sourcePath); // this should filter for jpg, gif, bmp, and png List <ScanInfo> toReturn = new List <ScanInfo>(); foreach (string imagePath in myPaths) { Debug.WriteLine("ImageScanner begin: " + imagePath); ScanInfo newInfo = new ScanInfo(imagePath); Result currentResult = _myQrSingleReader.decode( new BinaryBitmap( new HybridBinarizer( new BitmapLuminanceSource( (Bitmap)Bitmap.FromFile(imagePath) ) ) ), _myHints); if (currentResult != null) { Debug.WriteLine("ImageScan raw: " + currentResult.Text); string[] splitString = currentResult.Text.Split(_stringDelimiter); if (splitString != null) { // translate these foreach (string currCode in splitString) { CsvDataNode translatedCode = _idParser.translateId(currCode); if (translatedCode != null) { newInfo.Properties[translatedCode.type] = translatedCode.name; // this should never be null } } } else { Debug.WriteLine("ImageScanner invalid raw"); } } else { Debug.WriteLine("ImageScan null scan"); } toReturn.Add(newInfo); } return(toReturn); }
private void ScanPreviewBuffer() { try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); Dispatcher.BeginInvoke(() => DisplayResult(result.Text)); } catch { } }
private static Result DecodeQRCode(Bitmap bm) { Result decodeResult = null; try { QRCodeReader reader = new QRCodeReader(); BitmapLuminanceSource source = new BitmapLuminanceSource(bm); BinaryBitmap bb = new BinaryBitmap(new HybridBinarizer(source)); decodeResult = reader.decode(bb); } catch (Exception ex) { logger.Error(ex.Message); return(null); } return(decodeResult); }