[Zxing , QR Sample ] C# 에서 QR 라이브러리 사용하기





실버라이트 용 QR 라이브러리도 코드플렉스에 있지만.. 요걸 사용하고 싶었다 .

그런데 요놈은 c# 용 레퍼런스가 아무것도 없었다 . 자바와 ios 는 잘되어 있던데 .,

그래서 AS3 용 코드를 보고 어영부영 따라해 보았다.










using
System; using System.Drawing; using System.Windows.Forms; using AForge.Video.DirectShow; using AForge.Controls; using System.Collections; using com.google.zxing; using com.google.zxing.common; using com.google.zxing.qrcode; using trace; namespace Xing_TEST { public partial class Form1 : Form { public static traceDele trace = new traceDele(traceCS.traceMethod); public Form1() { InitializeComponent(); } //aforge player private VideoSourcePlayer player; //render Data private Bitmap captureData; //render Region private Rectangle captureBound; //renderTimer private Timer timer; //qr member private Reader reader; private Hashtable hint; protected override void OnLoad(EventArgs e) { //aforge initialize player = new VideoSourcePlayer(); player.Width = 320; player.Height = 240; FilterInfoCollection device = new FilterInfoCollection(FilterCategory.VideoInputDevice); VideoCaptureDevice cam = new VideoCaptureDevice(device[0].MonikerString); player.VideoSource = cam; player.Start(); this.Controls.Add(player); //captureData initialize captureBound = new Rectangle(player.Location.X , player.Location.Y , player.Width+100, player.Height); captureData = new Bitmap(player.Width, player.Height); Graphics g = Graphics.FromImage(captureData); //QR initialize reader = new QRCodeReader(); hint = new Hashtable(); hint.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE); //render timer initialize timer = new Timer(); timer.Tick += new EventHandler(timer_Tick); timer.Interval = 30; timer.Start(); base.OnLoad(e); } void timer_Tick(object sender, EventArgs e) { //capture DrawToBitmap(captureData, captureBound); pictureBox1.Image = captureData; //QR processing RGBLuminanceSource source = new RGBLuminanceSource(captureData, captureData.Width, captureData.Height); BinaryBitmap img = new BinaryBitmap(new GlobalHistogramBinarizer(source)); Result result = null; try { //QR success result = reader.decode(img, hint); } catch{} if (result == null) { //QR fail label1.Text = "no decode!"; } else { //QR Success label1.Text = result.Text; label2.Text = result.BarcodeFormat.ToString(); } } //close protected override void OnClosed(EventArgs e) { trace("Close!"); timer.Stop(); player.SignalToStop(); player.WaitForStop(); base.OnClosed(e); } } }
Yamecoder 야매코더_
tags : , ,
C# 2011.01.07 18:24
Powerd by Tistory, designed by criuce
rss