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); } }
private void openQRCodeToolStripMenuItem_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { Filter = "All Supported|*.png;*.jpg;*.bmp;*.gif|PNG Files|*.png|Jpeg Files|*.jpg|Bitmap Files|*.bmp|GIF Files|*.gif" }; if (ofd.ShowDialog() != DialogResult.OK) return; try { var file = new FileStream(ofd.FileName, FileMode.Open); var bmp = new Bitmap(Image.FromStream(file)); file.Close(); var binary = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height))); var reader = new QRCodeReader(); var hashtable = new Hashtable(); hashtable.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.QR_CODE); hashtable.Add(DecodeHintType.TRY_HARDER,true); var result = reader.decode(binary, hashtable); var byteArray = (byte[])((ArrayList)result.ResultMetadata[ResultMetadataType.BYTE_SEGMENTS])[0]; load_QR_data(byteArray); } catch (ReaderException ex) { MessageBox.Show("Error Loading:" + Environment.NewLine + ex.Message); } catch (InvalidOperationException ex) { MessageBox.Show("Error Loading:" + Environment.NewLine + ex.Message); } }
void decoder_DoWork(object sender, DoWorkEventArgs e) { Bitmap bmp = (Bitmap)e.Argument; QRCodeReader reader = new QRCodeReader(); RGBLuminanceSource source = new RGBLuminanceSource(bmp, bmp.Width, bmp.Height); BinaryBitmap binDecode = new BinaryBitmap(new HybridBinarizer(source)); String decodedString = ""; Result result; try { result = (Result)reader.decode(binDecode); decodedString = result.Text; } catch (ReaderException) { decodedString = ""; } if (decodedString == "") { toolStripStatusLabel1.Text = "Scan a Player ID"; } else { String[] items = (decodedString).Split('|'); this.Invoke((MethodInvoker)delegate//run on UI thread { label_Name.Text = "Name: " + items[0]; label_Kill.Text = "Kill ID: " + items[1]; toolStripStatusLabel1.Text = "Decoded"; }); } }
private void menuQRCodeRead_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { Filter = @"All Supported|*.png;*.jpg;*.bmp;*.gif|PNG Files|*.png|Jpeg Files|*.jpg|Bitmap Files|*.bmp|GIF Files|*.gif" }; if (ofd.ShowDialog() != DialogResult.OK) return; try { var bmp = new Bitmap(Image.FromFile(ofd.FileName)); var binary = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(bmp, bmp.Width, bmp.Height))); var reader = new QRCodeReader(); var result = reader.decode(binary); var byteArray = (byte[])((ArrayList)result.ResultMetadata[ResultMetadataType.BYTE_SEGMENTS])[0]; var ms = new MemoryStream(byteArray); gridControl.LevelData.Read(ms); ms.Close(); DataToGui(); } catch (ReaderException ex) { MessageBox.Show(@"Error Loading:" + Environment.NewLine + ex.Message); } }