Showing posts with label Webcam. Show all posts
Showing posts with label Webcam. Show all posts

Monday, October 11, 2010

Capture And Save An Image with A Webcam

Flex Builder 4 Flash Video Flash Video Flash Video


Webcams can serve as a camera that you can use with ActionScript. The Camera class is built into ActionScript allowing you to build applications that include webcams. Setting up a webcam in Flash is easy. You can use the webcam in a project to streaming video for video chat (with a media server account),or use as a tool to take a photo for members of your site.

Record and Save The Image

  1. Get and install the ActionScript Core Library
  2. Import the JGPEncoder
  3. Create 2 MC and name capture_mc and save_mc
  4. After entering the code change the X & Y values to place the 2 cameras where you want.
  5. Use the FileReference.save() method and pass in the ByteArray and the file name.
  6. Test the movie and activate the camera.

The Code

import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;
import flash.net.FileReference;

//Set the quality of the bitmap
var quality:int = 90;
var bandwidth:int = 0;
var cam:Camera = Camera.getCamera();

//camOn will be used later to turn off the webcam
var camOn:Boolean = false;

cam.setQuality(bandwidth, quality);
var video:Video = new Video(241,185);
video.attachCamera(cam);
video.x = 30;
video.y = 50;
addChild(video);

var bitmapData:BitmapData = new BitmapData(video.width,video.height);

var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 285;
bitmap.y = 50;
addChild(bitmap);

//Button functions
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);

save_mc.buttonMode = true;
save_mc.addEventListener(MouseEvent.CLICK,saveImage);

function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
}

var i:Number=1;
var fileRef:FileReference = new FileReference();

function saveImage(e:MouseEvent):void{
var encoder:JPGEncoder = new JPGEncoder();
var ba:ByteArray = encoder.encode(bitmapData);
fileRef.save(ba,"capture"+i+".jpg");
i++;
}

//Turn the camera on and off
stop_btn.addEventListener(MouseEvent.CLICK, movieStop);

function movieStop(e:Event) {
if (camOn){
video.attachCamera(null);
} else {
video.attachCamera(cam);
}

camOn = !camOn;

}

 

ActionScript 3.0 Reference

Camera — final class, package flash.media
Use the Camera class to capture video from the client system's camera.

CAMERA
— Constant Static Property, class flash.system.SecurityPanelWhen passed to Security.showSettings(), displays the Camera panel in Flash Player Settings.

CameraRoll — class, package flash.mediaThe CameraRoll class allows you to save image data to a system's "camera roll." AIR profile support: This feature is supported on mobile devices, but it is not supported on desktop operating systems.

Wednesday, October 6, 2010

Activate A Webcam with Actionscript

Flex Builder 4 Flash Video Flash Video Flash Video


Activate A Webcam with Actionscript

Webcams can serve as a source of video data that you can use with ActionScript. The Camera class is built into ActionScript allowing you to build applications that include webcams.

Ways to get the camera to work

  1. Inside the library panel menu, select New Video
  2. Drag an instance of the video to the stage
  3. Size the video
  4. Give the empty video shell the instance name of myCam
  5. Copy and paste the code below
  6. Test the movie and activate the camera.

The Code

import flash.media.Camera;
import flash.media.Video;

var camera:Camera = Camera.getCamera();

if (camera != null) {

myCam.attachCamera(camera);

} else {
trace("You need a camera.");

}

stop();


ActionScript 3.0 Reference

Camera — final class, package flash.media
Use the Camera class to capture video from the client system's camera.

CAMERA
— Constant Static Property, class flash.system.SecurityPanelWhen passed to Security.showSettings(), displays the Camera panel in Flash Player Settings.

CameraRoll — class, package flash.mediaThe CameraRoll class allows you to save image data to a system's "camera roll." AIR profile support: This feature is supported on mobile devices, but it is not supported on desktop operating systems.

Related Posts Plugin for WordPress, Blogger...