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=qrReader.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";}
}public function getAllHints():HashTable
{var ht:HashTable=new HashTable;ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);return ht;
}
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;btn.label = "Scan Now";lbl.text = "";cameraStarted = true;
}
else {lbl.text = "no camera found";
}