跳到主要內容

ActionScript3.0 QRcode應用

QRcode是啥呢?
維基說得很清楚! Q = quick, R = response,二維條碼,在這條碼裡面可以夾帶許多資訊,例如數字、字母、漢字等等。

那如何用FLASH去製作QRcode?以下有幾個步驟。
1.新增視訊
2.將視訊圖檔用BitmapData存下來
3.設定存檔擷取圖像
4.給外部AS比對圖檔(使用zxing,快去下載來用!)
5.自己製作屬於自己的QRcode
6.GO!

步驟一:(程式碼)
var camera:Camera = Camera.getCamera();
var videoDisplay:Video = new Video(300,300);

camera.setMode(300, 300, 24);
camera.setQuality(0, 100);
videoDisplay.attachCamera(camera);
addChild(videoDisplay);
步驟二:
bmd = new BitmapData(300,300);
bmd.draw(videoDisplay, null, null, null, null, true);
步驟三:
function decodeSnapshot():void
{
 videoDisplay.cacheAsBitmap = true;
 decodeBitmapData(bmd, 300, 300);
 bmd.dispose();
 bmd = null;
}
步驟四:
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 = getAllHints();
 var res:Result = null;
 try
 {
  res = _myReader.decode(bitmap,ht);
 }
 catch (event:Error)
 {
 }

 if (res == null)
 {
  videoDisplay.clear();
 }
 else
 {
  var parsedResult:ParsedResult = ResultParser.parseResult(res);
  var QRcodeResult:String = parsedResult.getDisplayResult();
 }
}

function getAllHints()
{
 var ht:HashTable = new HashTable  ;
 ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
 return ht;
}

留言