Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Using zxing for Bar Codes. Not Found exception.

Explorer ,
Apr 09, 2013 Apr 09, 2013

Hello:

I'm trying to scan UPCA, UPCE, or CODE128 barcodes on my air mobile application.  I have followed a couple examples to try to get on the right path:

http://cookbooks.adobe.com/post_How_do_I_add_a_QR_code_reader_to_my_Flex_mobile_ap-19074.html

http://forums.adobe.com/thread/890506

I'm using an image size of 320 x 240.  Set the camera to quality 100.  Has anyone gotten this to work correctly?

Thank You,

  -Eric Bloms

import com.google.zxing.BarcodeFormat;

                              import com.google.zxing.BinaryBitmap;

                              import com.google.zxing.BufferedImageLuminanceSource;

                              import com.google.zxing.DecodeHintType;

                              import com.google.zxing.Result;

                              import com.google.zxing.client.result.ParsedResult;

                              import com.google.zxing.client.result.ResultParser;

                              import com.google.zxing.common.GlobalHistogramBinarizer;

                              import com.google.zxing.common.flexdatatypes.HashTable;

                              import com.google.zxing.qrcode.QRCodeReader;

                              import mx.core.UIComponent;

                              import spark.events.ViewNavigatorEvent;

 

                              private var camera:Camera;

                              private var cameraVideo:MovieClip;

                              private var videoDisplay:Video=new Video(320, 240);

                              private var qrReader:QRCodeReader;

                              private var bmd:BitmapData;

                              private var cameraStarted:Boolean = false;

                              private var detectChange:Timer;

 

                              protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void

                              {

                                        qrReader = new QRCodeReader();

                                        if(!cameraStarted)

                                        {

                                                  if(Camera.isSupported)

                                                  {

                                                            camera = Camera.getCamera();

                                                            camera.setQuality(0, 100);

                                                            camera.setMode(320, 240, 8, false);

 

                                                            videoDisplay.attachCamera(camera);

                                                            videoDisplay.width = camera.width;

                                                            videoDisplay.height = camera.height;

                                                            videoDisplay.x = 0;

                                                            videoDisplay.y = 0;

                                                            videoDisplay.cacheAsBitmap = true;

                                                            //videoDisplay.rotation=90;

                                                            sv.addChild(videoDisplay);

 

                                                            var uic:UIComponent = new UIComponent();

                                                            uic.graphics.lineStyle(3,0xFF0000);

                                                            uic.graphics.drawRect(0,0,260,180);

                                                            uic.horizontalCenter = uic.verticalCenter = 0;

                                                            uic.width = videoDisplay.width;

                                                            uic.height = videoDisplay.height;

                                                            sv.addChild(uic);

 

                                                            cameraStarted = true;

                                                            TimerExample();

                                                  }

                                                  else

                                                  {

                                                            scanLabel.text = "Error: No camera found.";

                                                  }

                                        }

                              }

 

                              public function TimerExample():void

                              {

                                        detectChange=new Timer(1888);

                                        detectChange.addEventListener(TimerEvent.TIMER, decodeSnapshot);

                                        detectChange.start();

                              }

 

                              private function focusCamera():void

                              {

                                        camera = Camera.getCamera();

                                        camera.setQuality(0, 100);

                                        camera.setMode(320, 240, 8, false);

                                        camera.setLoopback(false);

                                        videoDisplay.attachCamera(camera);

                              }

 

                              protected function scanButton_clickHandler(event:MouseEvent):void

                              {

                                        decodeSnapshot(null);

                              }

 

                              private function decodeSnapshot(event:TimerEvent):void

                              {

                                        scanLabel.text = "Checking...";

                                        bmd = new BitmapData(320, 240);

                                        bmd.draw(videoDisplay, null, null, null, null, true);

                                        videoDisplay.cacheAsBitmap = true;

                                        videoDisplay.cacheAsBitmapMatrix = new Matrix;

                                        decodeBitmapData(bmd, 320, 240);

                                        bmd.dispose();

                                        bmd = null;

                                        System.gc();

                              }

 

                              public function decodeBitmapData(bmpd:BitmapData, width:int, height:int):void

                              {

                                        var lsource:BufferedImageLuminanceSource=new BufferedImageLuminanceSource(bmpd);

                                        var bitmap:BinaryBitmap=new BinaryBitmap(new GlobalHistogramBinarizer(lsource));

 

                                        var ht:HashTable=null;

                                        ht=this.getAllHints();

 

                                        var res:Result=null;

                                        try {

                                                  res=qrReader.decode(bitmap, ht);

                                        }

                                        catch (event:Error) {

                                                  scanLabel.text = event.name + " - " +event.message + " - " + event.getStackTrace();

                                                  trace(event.name + " - " +event.message + " - " + event.getStackTrace());

                                        }

 

                                        if (res == null) {

                                                  videoDisplay.clear();

                                                  scanLabel.text="nothing decoded";

                                        }

                                        else {

                                                  var parsedResult:ParsedResult = ResultParser.parseResult(res);

                                                  scanLabel.text=parsedResult.getDisplayResult();

                                                  sv.removeChild(videoDisplay);

                                                  cameraStarted = false;

                                        }

                              }

 

                              public function getAllHints():HashTable

                              {

                                        var ht:HashTable = new HashTable();

                                        //ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);

                                        ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.UPC_E);

                                        ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.UPC_A);

                                        ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.CODE_128);

                                        ht.Add(DecodeHintType.TRY_HARDER, true);

 

                                        return ht;

                              }

TOPICS
Development
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Apr 09, 2013 Apr 09, 2013

Ok, if this helps anyone down the line:

I realized that my camera and video sizes were inconsistant and got rid of the white space.  Also, I was using an instance of QrReader() to try and read UPC_A and UPC_E formats.  The way that I found to work was using an instance of MultiFormatOneDReader() instead.

Translate
Explorer ,
Apr 09, 2013 Apr 09, 2013

I have made some changes to display the bitmap data on the screen after capturing and there is some whitespace on the bottom and right side of the image.  I'm experimenting with how I can get rid of this white space now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 09, 2013 Apr 09, 2013
LATEST

Ok, if this helps anyone down the line:

I realized that my camera and video sizes were inconsistant and got rid of the white space.  Also, I was using an instance of QrReader() to try and read UPC_A and UPC_E formats.  The way that I found to work was using an instance of MultiFormatOneDReader() instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines