Home > Flex/Air, Frameworks, RIA > Simple Webcam Capture Demo for Flex

Simple Webcam Capture Demo for Flex


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

  1. manpreet
    January 15, 2011 at 12:08 AM

    G8 JOB dude…………

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: