2011-11-24 97 views
0

基于http://www.remotesynthesis.com/post.cfm/adding-a-qr-code-reader-in-flex-on-android和zxing客户端示例代码,我尝试创建一个可以读取任何类型代码的应用程序。但在我的设备上,使用Qrcode时工作正常,但不适用于任何其他类型的代码,特别是条形码;我错在哪里?下面是代码 -FLEX - ZXing - Android,Mobile - 条码阅读器

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" title="Scanner"> 

    <fx:Script> 
     <![CDATA[ 
      import mx.core.BitmapAsset; 
      import com.google.zxing.common.BitMatrix; 
      import com.google.zxing.BarcodeFormat; 
      import com.google.zxing.BinaryBitmap; 
      import com.google.zxing.BufferedImageLuminanceSource; 
      import com.google.zxing.DecodeHintType; 
      import com.google.zxing.MultiFormatReader; 
      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.oned.EAN13Reader; 
      //import com.google.zxing.qrcode.QRCodeReader; 

      import flashx.textLayout.tlf_internal; 

      protected var camera:Camera; 
      private var videoDisplay:Video = new Video(300, 300); 
      private var myReader:MultiFormatReader; 
      private var bmd:BitmapData; 
      private var cameraStarted:Boolean = false; 


      protected function start_camera(event:MouseEvent):void 
      { 
       myReader = new MultiFormatReader(); 

       if(!cameraStarted){ 
        if(Camera.isSupported) { 
         camera = Camera.getCamera(); 
         camera.setMode(300, 300, 15); 

         videoDisplay.x = 295; 
         sv.addChild(videoDisplay); 

         videoDisplay.attachCamera(camera); 
         videoDisplay.rotation = 90; 

         btn.label = "Scan Now"; 
         lbl.text = ""; 
         cameraStarted = true; 
        } else { 
         lbl.text = "No camera found"; 
        } 
       } else { 
        decodeSnapshot(); 
       } 
      } 

      public function decodeSnapshot():void { 
       lbl.text = "Checking..."; 
       bmd = new BitmapData(300, 300); 
       bmd.draw(videoDisplay, null, null, null, null, true); 
       videoDisplay.cacheAsBitmap = true; 
       videoDisplay.cacheAsBitmapMatrix = new Matrix; 
       decodeBitmapData(bmd, 300, 300); 
       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 = myReader.decode(bitmap, ht); 
       } 

       catch (event:Error) { 

       } 

       if (res == null) { 
        videoDisplay.clear(); 
        lbl.text = "Nothing decoded"; 
       } else { 
        var parsedResult:ParsedResult = ResultParser.parseResult(res); 
        lbl.text = parsedResult.getDisplayResult(); 
        sv.removeChild(videoDisplay); 
        cameraStarted = false; 
        btn.label = "Start Camera"; 
       } 

      } 

      private function getAllHints():HashTable { 
       var ht:HashTable = new HashTable; 
       //ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.EAN_13); 
       return ht; 
      } 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <s:VGroup height="100%" width="100%" top="0" right="0" bottom="0" left="0" horizontalAlign="center"> 
     <s:VGroup width="100%" height="300" horizontalAlign="center" id="vg"> 
      <s:SpriteVisualElement id="sv" width="300" height="200" /> 
     </s:VGroup> 
     <s:VGroup horizontalAlign="center" > 
      <s:Button id="btn" width="220" height="36" label="Start Camera" 
         click="start_camera(event)"/> 
      <s:Label id="lbl" x="106" y="291" text=""/> 
     </s:VGroup> 
    </s:VGroup> 
</s:View> 
+0

我有同样的问题...你解决了吗? – Marcx

回答

1

camera.setMode(300, 300, 15);是错误的,使用:

this.camera.setMode(320, 240, 15, true); 

请记住,AS3版本的检测并不像斑马线的原生Android代码为强。

编辑: 读你的帖子错了,你必须添加一个你想要的格式的散列,并将其推入散列数组。