views:

487

answers:

2

Currently I am developing an application for decoding barcodes using mobile phones.

I have a problem with how to draw a line or a square on the camera screen to easily capture the barcode.

What is the easiest way of doing it?

+1  A: 

Unfortunately this isn't as easy as it sounds. If you have a preview image from a phone's camera then it's often rendered as an overlay. This means that the camera preview image doesn't actually form any part of your application's canvas and you can't interact directly with the pixels. The phone simply draws the preview on top of your appliction, completely out of your control.

If you draw a line on your screen, then it will be drawn underneath the preview image.

The way around this isn't too pretty. You need to actually capture an image from the camera. Unfortunately this means capturing a JPEG or a PNG file into a byte buffer. You then load this image using Image.createImage and render that to the screen. You can then safely draw on top of that.

This also has the undesirable downside of giving you an appalling frame-rate. You might want to enumerate all the possible file formats you can capture in and try them all to see which one is quickest.

izb
+1  A: 

You can do this by using OverlayControl, assumming that your target devices support it. I think i remember seeing a good example @ Sony Ericsson developer forums.

Edit: found this (does not involve use of OverlayControl)

Orr Matarasso