private void ScanPreviewBuffer() { if (_photoCamera == null) { return; } if (!_initialized) { return; } try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new ZXing.Common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); if (result != null) { OnDecodingCompleted(result); } } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
public BinaryBitmap GetImage(string file) { var fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", file); var bmp = new System.Drawing.Bitmap(fullName); var bin = new ZXing.Common.HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height)); var i = new BinaryBitmap(bin); return(i); }
private void ScanPreviewBuffer() { if (_photoCamera == null) { return; } if (!_initialized) { return; } // Don't scan too frequently // Check the minimum time between frames // as well as the min time between continuous scans var msSinceLastPreview = (DateTime.UtcNow - _lastAnalysis).TotalMilliseconds; if ((DateTime.UtcNow - _lastAnalysis).TotalMilliseconds < Options.DelayBetweenAnalyzingFrames || (_wasScanned && msSinceLastPreview < Options.DelayBetweenContinuousScans)) { return; } if (!IsAnalyzing) { return; } _wasScanned = false; _lastAnalysis = DateTime.UtcNow; try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new ZXing.Common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); if (result != null) { _wasScanned = true; OnDecodingCompleted(result); } } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
MemoryStream QRFromClipboard() { QRCodeReader redd = new QRCodeReader(); Bitmap bmp = (Bitmap)Clipboard.GetImage(); BitmapLuminanceSource blp = new BitmapLuminanceSource(bmp); pictureBox3.Image = bmp; Binarizer binarizer = new ZXing.Common.HybridBinarizer(blp); BinaryBitmap binBmp = new BinaryBitmap(binarizer); Result rr = redd.decode(binBmp); String dat = ""; byte[] payload = new byte[rr.RawBytes.Length]; FileStream ff = new FileStream("C:/DATASETS/incoming", FileMode.Create); for (int i = 0; i < rr.RawBytes.Length; i++) { ff.WriteByte(rr.RawBytes[i]); } ff.Close(); for (int i = 0; i < payload.Length; i++) { payload[i] = (byte)rr.RawBytes[i]; } MessageBox.Show(new String(UnicodeEncoding.Unicode.GetChars(payload))); MemoryStream fs = new MemoryStream(); BinaryWriter bw = new BinaryWriter(fs); fs.Write(payload, 0, payload.Length); fs.Seek(0, SeekOrigin.Begin); return(fs); }
public BinaryBitmap GetImage(string file) { var fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", file); //Try to find it from the source code folder if (!System.IO.File.Exists(fullName)) { fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "Images", file); } var bmp = new System.Drawing.Bitmap(fullName); var bin = new ZXing.Common.HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height)); var i = new BinaryBitmap(bin); return(i); }
public static List <QRCode> ExtractFrom(Image image) { List <QRCode> output = new List <QRCode>(); Bitmap bitmap = new Bitmap(image); ZXing.QrCode.QRCodeReader qr = new ZXing.QrCode.QRCodeReader(); ZXing.LuminanceSource source = new ZXing.BitmapLuminanceSource(bitmap); ZXing.Common.HybridBinarizer hybrid = new ZXing.Common.HybridBinarizer(source); ZXing.BinaryBitmap binBitmap = new ZXing.BinaryBitmap(hybrid); ZXing.Result[] multiresults = new ZXing.Multi.QrCode.QRCodeMultiReader().decodeMultiple(binBitmap); if (multiresults != null && multiresults.Length > 0) { foreach (ZXing.Result result in multiresults) { QRCode qrCode = new QRCode(result.Text); qrCode.Points = new PointF[result.ResultPoints.Length]; for (int i = 0; i < result.ResultPoints.Length; i++) { qrCode.Points[i] = new PointF(result.ResultPoints[i].X, result.ResultPoints[i].Y); } output.Add(qrCode); } } ZXing.Result singleresult = qr.decode(binBitmap); if (singleresult != null) { QRCode qrCode = new QRCode(singleresult.Text); qrCode.Points = new PointF[4]; qrCode.Points[0] = new PointF(singleresult.ResultPoints[0].X, singleresult.ResultPoints[0].Y); qrCode.Points[1] = new PointF(singleresult.ResultPoints[1].X, singleresult.ResultPoints[1].Y); qrCode.Points[2] = new PointF(singleresult.ResultPoints[2].X, singleresult.ResultPoints[2].Y); if (singleresult.ResultPoints.Length > 2) { qrCode.Points[3] = new PointF(singleresult.ResultPoints[3].X, singleresult.ResultPoints[3].Y); } output.Add(qrCode); } return(output); }
public static string QRDecoder(System.IO.Stream qrCodeFileStream) { var sKManagedStream = new SkiaSharp.SKManagedStream(qrCodeFileStream, true); var sKBitmap = SkiaSharp.SKBitmap.Decode(sKManagedStream); sKManagedStream.Dispose(); if (sKBitmap.IsEmpty) { sKBitmap.Dispose(); throw new Exception("未识别的图片文件"); } var w = sKBitmap.Width; var h = sKBitmap.Height; int ps = w * h; byte[] bytes = new byte[ps * 3]; int byteIndex = 0; for (var x = 0; x < w; x++) { for (var y = 0; y < h; y++) { var color = sKBitmap.GetPixel(x, y); bytes[byteIndex + 0] = color.Red; bytes[byteIndex + 1] = color.Green; bytes[byteIndex + 2] = color.Blue; byteIndex += 3; } } sKBitmap.Dispose(); var qRCodeReader = new ZXing.QrCode.QRCodeReader(); var rGBLuminanceSource = new ZXing.RGBLuminanceSource(bytes, w, h); var hybridBinarizer = new ZXing.Common.HybridBinarizer(rGBLuminanceSource); var binaryBitmap = new ZXing.BinaryBitmap(hybridBinarizer); var hints = new Dictionary <ZXing.DecodeHintType, object>(); hints.Add(ZXing.DecodeHintType.CHARACTER_SET, "utf-8"); var result = qRCodeReader.decode(binaryBitmap, hints); return(result != null ? result.Text : ""); }
public BinaryBitmap GetImage(string file) { var fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", file); var bmp = new System.Drawing.Bitmap(fullName); var bin = new ZXing.Common.HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height)); var i = new BinaryBitmap(bin); return i; }
private void ScanPreviewBuffer() { if (_photoCamera == null) return; if (!_initialized) return; try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new ZXing.Common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); if (result != null) OnDecodingCompleted(result); } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
private void ScanPreviewBuffer() { if (!IsAnalyzing) return; if (_photoCamera == null) return; if (!_initialized) return; // Don't scan too frequently // Check the minimum time between frames // as well as the min time between continuous scans var msSinceLastPreview = (DateTime.UtcNow - _lastAnalysis).TotalMilliseconds; if ((DateTime.UtcNow - _lastAnalysis).TotalMilliseconds < Options.DelayBetweenAnalyzingFrames || (_wasScanned && msSinceLastPreview < Options.DelayBetweenContinuousScans)) return; _wasScanned = false; _lastAnalysis = DateTime.UtcNow; try { _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY); var binarizer = new ZXing.Common.HybridBinarizer(_luminance); var binBitmap = new BinaryBitmap(binarizer); var result = _reader.decode(binBitmap); if (result != null) { _wasScanned = true; OnDecodingCompleted(result); } } catch (Exception) { // If decoding fails it will throw a ReaderException // and we're not interested in doing anything with it } }
public BinaryBitmap GetImage(string file) { var fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", file); //Try to find it from the source code folder if (!System.IO.File.Exists(fullName)) fullName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "Images", file); var bmp = new System.Drawing.Bitmap(fullName); var bin = new ZXing.Common.HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height)); var i = new BinaryBitmap(bin); return i; }