系统要求:Flash CS5以上(保证flashplayer播放器10.2以上),需要com.adobe.images.JPGEncoderr类,附件里面有。
打开flash CS5,新建AS3文档,舞台上放置一个按钮:,btn1
文档类文件PhotoSnap.as:- ‍package
- {
- import flash.media.*;
- import flash.display.*;
- import flash.net.*;
- import fl.controls.*;
- import flash.events.*;
- import flash.geom.*;
- import com.adobe.images.JPGEncoder;
- public class PhotoSnap extends Sprite
- {
- var Cam:Camera;
- var vid:Video;
- public function PhotoSnap():void
- {
- Cam = Camera.getCamera("0");
- if (Cam == null)
- {
- trace("无摄像头\n");
- }
- Cam.setMode(1280,720,10);
- Cam.setQuality(0,100);
- vid = new Video(160,90);
- vid.x = 20;
- vid.y = 50;
- vid.attachCamera(Cam);
- addChild(vid);
- btn1.addEventListener(MouseEvent.CLICK, savepic);
- }
- public function savepic(event:MouseEvent)
- {
- var jpgSource = new BitmapData(Cam.width,Cam.height);
- var myMatrix:Matrix=new Matrix();
- myMatrix.scale(8,8);
- //关键处,该处的值应该是由video的大小和camera设置的大小决定的。;
- jpgSource.draw(vid,myMatrix);
- var file:FileReference = new FileReference();
- var jpg:JPGEncoder = new JPGEncoder(100);
- file.save(jpg.encode(jpgSource),"b.jpg");
- }
- }
- }
复制代码 案例下载:
AS3摄像头拍照保存到本地.rar
(334.29 KB, 下载次数: 89)
|