Using zxing for Bar Codes. Not Found exception.
Hello:
I'm trying to scan UPCA, UPCE, or CODE128 barcodes on my air mobile application. I have followed a couple examples to try to get on the right path:
http://cookbooks.adobe.com/post_How_do_I_add_a_QR_code_reader_to_my_Flex_mobile_ap-19074.html
http://forums.adobe.com/thread/890506
I'm using an image size of 320 x 240. Set the camera to quality 100. Has anyone gotten this to work correctly?
Thank You,
-Eric Bloms
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.BufferedImageLuminanceSource;
import com.google.zxing.DecodeHintType;
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.qrcode.QRCodeReader;
import mx.core.UIComponent;
import spark.events.ViewNavigatorEvent;
private var camera:Camera;
private var cameraVideo:MovieClip;
private var videoDisplay:Video=new Video(320, 240);
private var qrReader:QRCodeReader;
private var bmd:BitmapData;
private var cameraStarted:Boolean = false;
private var detectChange:Timer;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
qrReader = new QRCodeReader();
if(!cameraStarted)
{
if(Camera.isSupported)
{
camera = Camera.getCamera();
camera.setQuality(0, 100);
camera.setMode(320, 240, 8, false);
videoDisplay.attachCamera(camera);
videoDisplay.width = camera.width;
videoDisplay.height = camera.height;
videoDisplay.x = 0;
videoDisplay.y = 0;
videoDisplay.cacheAsBitmap = true;
//videoDisplay.rotation=90;
sv.addChild(videoDisplay);
var uic:UIComponent = new UIComponent();
uic.graphics.lineStyle(3,0xFF0000);
uic.graphics.drawRect(0,0,260,180);
uic.horizontalCenter = uic.verticalCenter = 0;
uic.width = videoDisplay.width;
uic.height = videoDisplay.height;
sv.addChild(uic);
cameraStarted = true;
TimerExample();
}
else
{
scanLabel.text = "Error: No camera found.";
}
}
}
public function TimerExample():void
{
detectChange=new Timer(1888);
detectChange.addEventListener(TimerEvent.TIMER, decodeSnapshot);
detectChange.start();
}
private function focusCamera():void
{
camera = Camera.getCamera();
camera.setQuality(0, 100);
camera.setMode(320, 240, 8, false);
camera.setLoopback(false);
videoDisplay.attachCamera(camera);
}
protected function scanButton_clickHandler(event:MouseEvent):void
{
decodeSnapshot(null);
}
private function decodeSnapshot(event:TimerEvent):void
{
scanLabel.text = "Checking...";
bmd = new BitmapData(320, 240);
bmd.draw(videoDisplay, null, null, null, null, true);
videoDisplay.cacheAsBitmap = true;
videoDisplay.cacheAsBitmapMatrix = new Matrix;
decodeBitmapData(bmd, 320, 240);
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) {
scanLabel.text = event.name + " - " +event.message + " - " + event.getStackTrace();
trace(event.name + " - " +event.message + " - " + event.getStackTrace());
}
if (res == null) {
videoDisplay.clear();
scanLabel.text="nothing decoded";
}
else {
var parsedResult:ParsedResult = ResultParser.parseResult(res);
scanLabel.text=parsedResult.getDisplayResult();
sv.removeChild(videoDisplay);
cameraStarted = false;
}
}
public function getAllHints():HashTable
{
var ht:HashTable = new HashTable();
//ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.UPC_E);
ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.UPC_A);
ht.Add(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.CODE_128);
ht.Add(DecodeHintType.TRY_HARDER, true);
return ht;
}
