Once you have connected to a camera device you are most likely going to want to show a preview to your users.
Preview frames are provided through the
CameraEvent.VIDEO_FRAME event. This is dispacted
from a camera device whenever a preview frame is available. The event indicates that bitmap
data representing the current view through the camera device is available.
When you receive the event you can then query the extension for the frame buffer using the
getFrameBuffer function. This function takes a
ByteArray which will be filled with the
bitmap data of the preview frame.
ByteArrayis used to ensure we can transfer the data from the native side to your AS3 quickly, attempting to keep the frame rate of your preview frame as high as possible.
To render the data you should create an appropriately sized
BitmapData object and use the
setPixels to update the bitmap data from the
Firstly lets create the bitmap data:
Then in our event handler we update from the frame buffer.
We also suggest you rotate the container of your bitmap data to match the orientation of the
camera device. You should use the
device.info.orientation value to rotate appropriately.
See the example applications for demonstrations of this, and the following gists: