|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
此外,还支持α透明功能,能够设计人员在Flash视频中对诸如文本、矢量图像以及其它Flash元素等进行整合。
poluoluo中心提醒:Flash实例教程:启动摄像头摄影动画.
Flash实例教程:启动摄像头摄影动画。人人请看效果:(假如你的呆板的摄像头已翻开)
[media=wmv,700,340][/media]
源文件下载:http://www.webjx.com/files/soft/1_090712084454.zip
1.Createanewflashfile(Actionscript3.0)andsaveitascaptureWebcam.fla.
2.Rename‘layer1′to‘button’.Createabuttononthestage,convertittoamovieclipandgiveitaninstancenameofcapture_mc.
3.Createanewlayernamed‘actions’andwithitsfirstframeselectedopentheactionspanel.
Allthatwearegoingtodonowhappensintheactionscriptcode.
4.FirstweinitializeawebcambyattachingacameratoaVideoobjectthatweaddtothestage:
1.varcam:Camera=Camera.getCamera();
2.varvideo:Video=newVideo(320,240);
3.video.attachCamera(cam);
4.video.x=20;
5.video.y=20;
6.addChild(video);
5.Then,weneedtousetheBitmapandBitmapDataclassestostoretheimagethatwewanttocaptureanddisplayonthestage.
WestartbyimportingtheBitmapandBitmapDataclasses:
1.importflash.display.Bitmap;
2.importflash.display.BitmapData;
6.ThencreateanewBitmapDataobjectofthesameproportionsofthevideoobjecttostoretheBitmapDatacapturedfromtheplayingwebcam.
AndcreateabitmapobjecttodisplaythedatafromtheBitmapDataobjectandaddittothestage.
1.varbitmapData:BitmapData=newBitmapData(video.width,video.height);
2.
3.varbitmap:Bitmap=newBitmap(bitmapData);
4.bitmap.x=360;
5.bitmap.y=20;
6.addChild(bitmap);
7.Finally,aftersettingitsbuttonModepropertytotrue,weaddaClickeventlistenertoourbutton.ThiseventishandledbythecaptureImagefunctionthatdrawstheimagethatiscurrentlydisplayingfromthewebcamintoourbitmapDataobject.
1.capture_mc.buttonMode=true;
2.capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
3.
4.functioncaptureImage(e:MouseEvent):void{
5.bitmapData.draw(video);
6.}
8.Hereisthefinalcode:
01.importflash.display.Bitmap;
02.importflash.display.BitmapData;
03.
04.varcam:Camera=Camera.getCamera();
05.varvideo:Video=newVideo(320,240);
06.video.attachCamera(cam);
07.video.x=20;
08.video.y=20;
09.addChild(video);
10.
11.varbitmapData:BitmapData=newBitmapData(video.width,video.height);
12.
13.varbitmap:Bitmap=newBitmap(bitmapData);
14.bitmap.x=360;
15.bitmap.y=20;
16.addChild(bitmap);
17.
18.capture_mc.buttonMode=true;
19.capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
20.
21.functioncaptureImage(e:MouseEvent):void{
22.bitmapData.draw(video);
23.}
此外,还支持α透明功能,能够设计人员在Flash视频中对诸如文本、矢量图像以及其它Flash元素等进行整合。 |
|