Archive

Posts Tagged ‘project’

Simple Webcam Capture Demo for Flex

August 3, 2010 1 comment

I put together a simple demo of how you can capture an image from the webcam in Flex. Nothing super complex going on here once you see it.

Basically we use the Camera, VideoDisplay, and the Bitmap classes. The Camera allows us to do just what you expect prompting the user to connect to their camera. The Camera is then attached to the VideoDisplay component and we can see what the camera sees.

1.

2.

3.
var camera:Camera = Camera.getCamera();
4.
5.
if (camera)
6.
{
7.
videoDisplay.attachCamera(camera);
8.
}
9.
else
10.
{
11.
Alert.show(“Oops, we can’t find your camera.”);
12.
}
13.

14.

When we want to capture an image we create a new, empty Bitmap at the same size as the VideoDisplay, and we draw the output of the VideoDisplay to the image. We then write that image back to the stage so we can see it.

1.

2.

3.
var snap:BitmapData = new BitmapData(320, 240, true);
4.
var snapBmp:Bitmap = new Bitmap(snap);
5.

6.
snapBmp.width = 320;
7.
snapBmp.height = 240;
8.

9.
if(snapshotHolder.numChildren > 0)
10.
snapshotHolder.removeChildAt(0);
11.

12.
snapshotHolder.addChild(snapBmp);
13.
snap.draw(videoDisplay);
14.

15.

Demo: http://www.davidortinau.com/flash/WebcamCaptureDemo/WebcamCaptureDemo.html

Source: http://www.davidortinau.com/flash/WebcamCaptureDemo/srcview/index.html