使用FLEX实现简单WEB在线拍照功能


Flex2中的代码片段,用于实现拍照功能.
 1            private function getSnapshotJPEG():void {
 2                var jpegEnc:JPEGEncoder = new JPEGEncoder(100);
 3                var jpegData:ByteArray = jpegEnc.encode(cameraStream.getSnapshotBitmapData());
 4                
 5                //var req:URLRequest = new URLRequest('http://127.0.0.1/php/UploadImg.php');
 6                var req:URLRequest = new URLRequest('http://127.0.0.1/dotnet/FlexWebCam.aspx');
 7                var loader:URLLoader = new URLLoader();
 8                saveImageListeners(loader);
 9                //loader.addEventListener('complete', onComplete);
10                
11                req.contentType = 'applicatoin/octet-stream';
12                //req.contentType = 'multipart/form-data';
13                req.method = URLRequestMethod.POST;
14                req.data = jpegData;
15                
16                try {
17                    loader.load(req);                    
18                }
 
19                catch (error:Error) {
20                    trace('unable to load request');
21                }

22                
23                function saveImageListeners(dispatcher:IEventDispatcher):void {
24                    dispatcher.addEventListener(Event.COMPLETE, onComplete);
25                }

26                
27                function onComplete(e:Event):void {
28                    //navigateToURL(new URLRequest("http://127.0.0.1/php/UploadImg.php"),"_self");
29                    var loader:URLLoader = URLLoader(e.target);
30                    trace('返回数据:'+loader.data);
31                }
            
32            }


FLEX实现抓取图像,通过JPEGEncoder转换成ByteArray,返回.

剩下的工作简单了,获取图像保存而 已

php 实现

1$fp = fopen('php.jpg', 'wb');
2fwrite($fp, $GLOBALS['HTTP_RAW_POST_DATA']);
3fclose($fp);

C# 实现

1        System.Drawing.Image img = System.Drawing.Image.FromStream(Request.InputStream);
2        img.Save(@"D:\path\asp.jpg");
posted on 2010-06-05 14:44  念时  阅读(470)  评论(0编辑  收藏  举报

细节决定成败!态度决定一切!