На основе http://www.remotesynthesis.com/post.cfm/adding-a-qr-code-reader-in-flex-on-android и примера кода клиента zxing я попытался создать приложения, которые могут читать любой тип кода.Но на моем устройстве он работает нормально при использовании Qrcode, но не работает ни с каким другим типом кода, особенно с Barcode;Где я не прав?Вот код -
<?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>