public QRDecoder(BinaryBitmap xBitmap) { QRCodeReader xReader = new QRCodeReader(); // m_xResult = xReader.decode(xBitmap); }
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) { } }); }
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); }
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"); } }
/// <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); }
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); }
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); } }
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 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); } }
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(""); }
//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) { } } }
/// <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); }
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> /// Set up a Decoder, specify possible formats /// </summary> /// <param name="formats">Possible formats to decode</param> public Decoder(params Format[] formats) { reader = new QRCodeReader(); foreach (Format format in formats) { hints.Add(DecodeHintType.POSSIBLE_FORMATS, ConvertFormat(format)); } }
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)); }
public void StopScanning() { if (IsScanning) { IsScanning = false; _reader = null; } }
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; } }
/// <summary> /// Starts or restarts actively scanning the camera's preview buffer /// for a two-dimensional barcode. /// </summary> public void StartScanning() { if (!IsScanning && _initialized) { _reader = new QRCodeReader(); IsScanning = true; Scan(); } }
public void StopScanning() { if (IsScanning) { IsScanning = false; _reader = null; UninitializePhotoCamera(); } }
public ActionResult PatientScanner(string imagePath = "") { var qrCodePath = $"{Server.MapPath("~/QrCodePath")}\\{imagePath}"; var qrCodeReader = new QRCodeReader(qrCodePath); var decodeData = qrCodeReader.ReadQRCode(); var patientId = _objIPatient.GetPatientIdByQrCode(decodeData.QRCodeText); return(RedirectToAction("ViewBooking", new { id = 0, viewMessage = "", patientId = patientId })); }
public Pipeline() { // TODO: Inject index CameraReader = new CameraReader(2); MarkerDetector = new MarkerDetector(); QRCodeFinder = new QRCodeFinder(); QRCodeReader = new QRCodeReader(); CardManager = new CardManager(); AugmentedDrawer = new AugmentedDrawer(); }
private static byte[] ParseQR(Image q) { var bitmap = new Bitmap(q); var img = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height); var hybrid = new HybridBinarizer(img); var binaryMap = new BinaryBitmap(hybrid); var reader = new QRCodeReader().Decode(binaryMap, null); return(Array.ConvertAll(reader.RawBytes, a => (byte)a)); }
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 byte[] parseQR(Image q) { Bitmap bitmap = new Bitmap(q); var img = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height); var hybrid = new HybridBinarizer(img); BinaryBitmap binaryMap = new BinaryBitmap(hybrid); var reader = new QRCodeReader().decode(binaryMap, null); byte[] data = Array.ConvertAll(reader.RawBytes, (a) => (byte)(a)); return(data); }
void Start() { WebCamOutTexture.transform.localPosition = new Vector3(ScreenPropotion.x, ScreenPropotion.y, 0.0f); Vector2 tempVec2 = new Vector2(Screen.width * ScreenPropotion.width, Screen.height * ScreenPropotion.height); WebCamOutTexture.pixelInset = new Rect(-tempVec2.x * 0.5f, -tempVec2.y * 0.5f, tempVec2.x, tempVec2.y); QR = new QRCodeReader(); Application.RequestUserAuthorization(UserAuthorization.WebCam); for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; ++cameraIndex) { if (isFrontCamera) { if (WebCamTexture.devices[cameraIndex].isFrontFacing) { camTexture = new WebCamTexture(WebCamTexture.devices[cameraIndex].name); // Here we flip the GuiTexture by applying a localScale transformation // works only in Landscape mode WebCamOutTexture.transform.localScale = new Vector3(-ScreenPropotion.width * 2.0f, -ScreenPropotion.height * 2.0f, 1); } } else { if (!WebCamTexture.devices[cameraIndex].isFrontFacing) { camTexture = new WebCamTexture(WebCamTexture.devices[cameraIndex].name); // Here we flip the GuiTexture by applying a localScale transformation // works only in Landscape mode //WebCamOutTexture.transform.localScale = new Vector3(-1,-1,1); } } } OnEnable(); WebCamOutTexture.texture = camTexture; Renderer renderer = GetComponent <Renderer>(); renderer.material.mainTexture = camTexture; baseRotation = transform.rotation; camTexture.Play(); if (camTexture != null) { c = new Color32[camTexture.width * camTexture.height]; } else { WebCamOutTexture.GetComponent <GUITexture>().texture = nullTexture2D; } qrThread = new Thread(DecodeQR); qrThread.Start(); }
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 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); } }
// private BarcodeReader _myBarcodeReader; // private BarcodeReader _myBarcodeReader2; // private BarcodeReader _myBarcodeReader3; public ImageScanner(char stringDelimiter, IdTranslator idParser) { _idParser = idParser; _myHints = new Dictionary <DecodeHintType, object>(); _myHints.Add(DecodeHintType.TRY_HARDER, true); _stringDelimiter = stringDelimiter; // _myQrReader = new QRCodeMultiReader(); _myQrSingleReader = new QRCodeReader(); // _myBarcodeReader = new BarcodeReader(null, bitmap => new BitmapLuminanceSource(bitmap), luminance => new GlobalHistogramBinarizer(luminance)) { AutoRotate = true, Options = new DecodingOptions { TryHarder = true, PossibleFormats = new List<BarcodeFormat>{BarcodeFormat.QR_CODE} }, TryInverted = true }; // _myBarcodeReader2 = new BarcodeReader(null, bitmap => new BitmapLuminanceSource(bitmap), luminance => new GlobalHistogramBinarizer(luminance)) { AutoRotate = true, Options = new DecodingOptions {TryHarder = true, PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.CODE_128}}, TryInverted = true }; // _myBarcodeReader3 = new BarcodeReader {AutoRotate = true, Options = new DecodingOptions {TryHarder = true, PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.CODE_128}}, TryInverted = true}; }
private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e) { var width = Convert.ToInt32(_photoCamera.PreviewResolution.Width); var height = Convert.ToInt32(_photoCamera.PreviewResolution.Height); _luminance = new PhotoLuminanceSource(width, height); _reader = new QRCodeReader(); Dispatcher.BeginInvoke(() => { _previewTransform.Rotation = _photoCamera.Orientation; _timer.Start(); }); }
public void StopScanning() { if (IsScanning) { IsScanning = false; _reader = null; } if (timer != null) { timer.Stop(); } }
public void OnTrackablesUpdated() { try { if (!isFrameFormatSet) { isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.GRAYSCALE, true); } cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE); UpdateCamTex(cameraFeed); tempText = ""; tempText = new QRCodeReader().decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight).Text; //tempText = new QRCodeReader().decode(vDecodeBytes, UnityCamTex.width, UnityCamTex.height).Text; } catch(Exception e) { // Fail to detect QR Code! // vDebugText = "Failed: " + e.InnerException.Message ; } finally { if (!string.IsNullOrEmpty(tempText)) { //http://www.unet.univie.ac.at/~a0701760/terrorzwerg/TerrorzwergClient.apk?Zwegdata=127.0.0.1:666,ASD-A080a-d080a8d-0ad;0 if( GameData.instance.ipAdress == ""){ qrText = tempText.Split(new string[]{"Zwegdata="}, StringSplitOptions.None)[1]; string AddressPart = qrText.Split(';')[0]; GameData.instance.ipAdress = AddressPart.Split(':')[0]; AddressPart = AddressPart.Split(':')[1]; GameData.instance.port = int.Parse(AddressPart.Split(',')[0]); GameData.instance.networkGUID = AddressPart.Split(',')[1]; GameData.instance.playerId = int.Parse(qrText.Split(';')[1]); // connect Application.LoadLevel("Client_noMinimap"); qrText = null; } qrText = null; } else{ GameData.instance.ipAdress = ""; } } }
public void OnTrackablesUpdated() { try { if(!isFrameFormatSet) { isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.GRAYSCALE, true); } cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE); tempText = new QRCodeReader().decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight).Text; } catch { // Fail detecting QR Code! } finally { if(!string.IsNullOrEmpty(tempText)) { qrText = tempText; } } }