Skip to main content
Inspiring
August 12, 2011
Answered

QR Code Decoding/Reading and iOS

  • August 12, 2011
  • 2 replies
  • 15179 views

Okay, this is driving me... insane.

I'm trying to implement a QR code reader in my iOS application (specifically for IPhone 4). I have tried THREE count em THREE different libraries and each one does not work. THEY ALL WORK PERFECTLY IN SIMULATOR BUT DO NOT WORK ON MOBILE DEVICE

1. I tried zxing bar code library which has an actionscript port.

On IPHONE 4: The application freezes (no error is thrown on remote debugging). I tried clipping the video source so not as big of a bitmap data is processed and it still freezes! (Actually the frames update maybe every 7-8 seconds)

2. I tried libspark's qr decode

Works perfectly in emulator.

On IPHONE 4: Same as Zxing... freezes (no error is thrown in remote debuggin).

3. Someone used Quasimondo's adaptive filter library to extend libspark's qr code library. I tried that and clipped the rectangle

On IPHONE 4: An error is thrown (via remote debugging) - one that isn't thrown in the emulator (it works perfectly in emulator). It APPEARS (although it's not easy to investigate) that the error is stemming from the air export not supporting pbj files (pixel bender/shaderjob stuff) - is that not supported in IPhone 4?

So it appears that there is a problem when you try and process bitmapdata on an IPhone... I've tried different render modes (gpu) and it didn't do anything for me.

DOES ANYONE know of any libraries that read QR codes? I really love developing ios stuff with AS3... Has anyone managed to use one of these libaries ??

This topic has been closed for replies.
Correct answer Innovatology

Well, if all 3 libraries fail, then maybe you are doing something wrong... ;-)

Probably not good news for you, but I've used the zxing library on both Android and BlackBerry with no problem at all.

Are you reducing the camera resolution to a sensible level, e.g. 320x240 or 640x480? If you're trying to process a  5-megapixel image every cycle, that could cause a problem.

Also, snap a bitmap from your video feed every second or so with a timer, then and analyze that. You really don't need to try to decode 25 barcodes a second.

Otherwise: post a code snippet, so we can see what you're doing.

2 replies

sbhave
Participating Frequently
February 14, 2013

I have written ANE version for ZBar [I have extended http://code.google.com/p/qr-zbar-ane/ to add more features and to support Android as well] that works on Android and iOS over same ActionScript API. It works similar to CameraUI i.e. I open Native Activity/ViewController that scans and sends the data to AIR app as an async event.

I have developed this for one of my projects. If anyone is interested revert back on this thread itself.

Regards,

sbhave

Participating Frequently
May 8, 2013

hello sbhave

thanks for create this ANE,it's fast and useful!

And I am wondering to know is this possible to lauch the scan without the native scan UI (the UI with a cancel button) ?

thanks for it.

Best

Yang,HS

Innovatology
InnovatologyCorrect answer
Participating Frequently
August 13, 2011

Well, if all 3 libraries fail, then maybe you are doing something wrong... ;-)

Probably not good news for you, but I've used the zxing library on both Android and BlackBerry with no problem at all.

Are you reducing the camera resolution to a sensible level, e.g. 320x240 or 640x480? If you're trying to process a  5-megapixel image every cycle, that could cause a problem.

Also, snap a bitmap from your video feed every second or so with a timer, then and analyze that. You really don't need to try to decode 25 barcodes a second.

Otherwise: post a code snippet, so we can see what you're doing.

K2xL_comAuthor
Inspiring
August 13, 2011

Thanks for the response.

At first I looked at my code and i was just doing a 320,240... but then i realized i added it to a movieclip and stretched that. Instead of passing the original 320,240 clip i was passing in the stretched clip (doh).

I fixed it and trying again and will let you know what happens.

K2xL_comAuthor
Inspiring
August 13, 2011

So there is not freezing anymore, but I can't get the Iphone to read qr code :-(. Reads it fine on emulator but it just can't detect it on iphone

cam = Camera.getCamera();

cam.setMode(320, 240, 20, false);

cam.setQuality(0, 100);

cameraVideo.attachCamera(cam);

cameraVideo.width = cam.width;

cameraVideo.height = cam.height;

cameraVideo.cacheAsBitmap = true;

cameraVideoContainer.addChild(cameraVideo); // for actually what appears on screen

cameraVideoContainer.width = stage.stageWidth;

cameraVideoContainer.height = stage.stageHeight;

bitmapDataSnapshot = new BitmapData(cameraVideo.width, cameraVideo.height);

And the way I do it is i have a timer run every 250 milliseconds and take a snapshot.

bitmapDataSnapshot.draw(cameraVideo, null, null, null, null,false);

and then pass it into

public function decodeBitmapData(bmpd : BitmapData) : 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(e : Error) {
// trace(e);
}
if (res != null) {
var parsedResult : ParsedResult = ResultParser.parseResult(res);
trace("Result::: " + parsedResult.getDisplayResult());
onQrDecodeComplete(parsedResult.getDisplayResult());
}
}