我正在使用flex 4.6来构建移动应用程序,我想在相机检测到它时动态获取qr代码,所以我使用zing库来获取它,按下按钮时效果很好,但我想制作没有按钮,相机打开并检查它我建立一个计时器重复每1毫秒但相机的帧变得太慢我怎么能提高它的性能成为相机的正常速度。 / p>
代码段:
protected function tryAgain(event:TimerEvent):void
{
videoDisplay.removeEventListener(Event.REMOVED,button1_clickHandler);
System.gc();
decodeSnapshot();
}
protected function onTimerComplete():void
{
lbl.text="finished";
}
protected function button1_clickHandler(event:MouseEvent):void
{
if (!cameraStarted) {
if (Camera.isSupported)
{
camera=Camera.getCamera();
camera.setMode(360, 360, 24);
videoDisplay.x = 360;
sv.addChild(videoDisplay);
videoDisplay.attachCamera(camera);
videoDisplay.rotation=90;
qrReader=new QRCodeReader;
lbl.text = "";
cameraStarted = true;
decodeSnapshot();
}
else {
lbl.text = "No Camera ";
}
}
else {
decodeSnapshot();
}
}
public function decodeSnapshot():void
{
myTimer.stop();
lbl.text="Check in progress";
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 getAllHints():HashTable
{
var ht:HashTable=new HashTable;
ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
return ht;
}
public var tempObj:Object = new Object();
protected var myTimer:Timer = new Timer(1,0);
protected var saveManager:PersistenceManager = new PersistenceManager();
public var userName:String;
public var pass:String;
public var qr:String;
private var _data:Object;
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) {
}
if (res == null) {
videoDisplay.clear();
myTimer.addEventListener(TimerEvent.TIMER , tryAgain);
myTimer.start();
}
else {
myTimer.removeEventListener(TimerEvent.TIMER , tryAgain);
camera.removeEventListener(ActivityEvent.ACTIVITY,button1_clickHandler);
var parsedResult:ParsedResult=ResultParser.parseResult(res);
lbl.text=parsedResult.getDisplayResult();
var saveManager:PersistenceManager = new PersistenceManager();
saveManager.setProperty("QRstring", parsedResult.getDisplayResult());
videoDisplay.clear();
sv.removeChild(videoDisplay);
cameraStarted = false;
btn.visible=false;
qRcode(userName , pass,qr, lbl.text);
}
}
更新:任何人都可以帮助我在移动时不用停止框架的情况下如何处理相机 我尝试在用户打开相机,扫描仪在后面工作,扫描相机继续工作,但我不能这样做。
提前感谢您的任何帮助或建议。
答案 0 :(得分:0)
我正在使用zing库。当我使用名为" TRY_HARDER"
的提示类型时,我遇到了相机性能问题添加提示的代码如下所示:
var ht:HashTable=new HashTable;
ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.QR_CODE);
ht.Add(DecodeHintType.TRY_HARDER,true);
var res:Result = myReader.decode(bitmap, ht);