快速业务通道

Flash实例教程:启动摄像头拍照动画

作者 凌众技术 来源 网页制作 浏览 发布时间 2012-03-08

Flash实例教程:启动摄像头拍照动画。大家请看效果:(如果你的机器的摄像头已经打开)

源文件下载:http://www.webjx.com/files/soft/1_090712084454.zip

1. Create a new flash file (Actionscript 3.0) and save it as captureWebcam.fla.

2. Rename ‘layer 1′ to ‘button’. Create a button on the stage, convert it to a movie clip and give it an instance name of capture_mc.

3. Create a new layer named ‘actions’ and with its first frame selected open the actions panel.
All that we are going to do now happens in the actionscript code.

4. First we initialize a webcam by attaching a camera to a Video object that we add to the stage:

1.var cam:Camera = Camera.getCamera();
2.var video:Video = new Video(320,240);
3.video.attachCamera(cam);
4.video.x = 20;
5.video.y = 20;
6.addChild(video);
5. Then, we need to use the Bitmap and BitmapData classes to store the image that we want to capture and display on the stage.
We start by importing the Bitmap and BitmapData classes:

1.import flash.display.Bitmap;
2.import flash.display.BitmapData;
6. Then create a new BitmapData object of the same proportions of the video object to store the BitmapData captured from the playing webcam.
And create a bitmap object to display the data from the BitmapData object and add it to the stage.

1.var bitmapData:BitmapData = new BitmapData(video.width,video.height);
2. 
3.var bitmap:Bitmap = new Bitmap(bitmapData);
4.bitmap.x = 360;
5.bitmap.y = 20;
6.addChild(bitmap);
7. Finally, after setting its buttonMode property to true, we add a Click event listener to our button. This event is handled by the captureImage function that draws the image that is currently displaying from the webcam into our bitmapData object.

1.capture_mc.buttonMode = true;
2.capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
3. 
4.function captureImage(e:MouseEvent):void {
5.   bitmapData.draw(video);
6.}
8. Here is the final code :

01.import flash.display.Bitmap;
02.import fla

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号