user1081305
user1081305

Reputation: 51

Detecting QR code using zxing

I'm working on detecting the qrcode. My requirement is when the user show’s his/her QR code to the camera, the program has to detect and draw one box around the QR code. I’m using zxing library + C#. I searched many things but I’m not able to find any samples in this. Kindly anyone help me in this.

Upvotes: 3

Views: 5653

Answers (1)

eNaught
eNaught

Reputation: 91

You can use the detector class for this. The detector constructor takes a BitMatrix object as its sole argument which can be obtained from the BlackMatrix property of the BinaryBitmap object...

public string Detect(Bitmap bitmap)
    {
        try
        {
            com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            var binarizer = new HybridBinarizer(source);
            var binBitmap = new BinaryBitmap(binarizer);
            BitMatrix bm = binBitmap.BlackMatrix;
            Detector detector = new Detector(bm);
            DetectorResult result = detector.detect();

            string retStr = "Found at points ";
            foreach (ResultPoint point in result.Points)
            {
                retStr += point.ToString() + ", ";
            }

            return retStr;
        }
        catch
        {
            return "Failed to detect QR code.";
        }
    }

Upvotes: 2

Related Questions