2011-11-24 68 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代碼爲強。

編輯: 讀你的帖子錯了,你必須添加一個你想要的格式的散列,並將其推入散列數組。