宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > AS2与AS3技术

[AS3]as3+php保存截取摄像头图片源代码

2016-10-13 00:16:48 点击量:10 标签: 收藏本文

做了一个类似的应用,现将源代码公布。(请自行配置php和gd2库)  as3:(放到帧上,可自行修改移至相关class)

  1. function clickHandler(e:MouseEvent):void 
  2.     var bitmapdata:BitmapData = new BitmapData(video.width, video.height); 
  3.     bitmapdata.draw(video); 
  4.     var jpgEncoder:JPGEncoder = new JPGEncoder(80);//图片质量 
  5.     var jpgStream:ByteArray = jpgEncoder.encode(bitmapdata); 
  6.     var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); 
  7.     var jpgURLRequest:URLRequest = new URLRequest ("http://localhost/jpg_encoder_download.php?name=camera.jpg"); //此web url请自行修改 
  8.     jpgURLRequest.requestHeaders.push(header); 
  9.     jpgURLRequest.method = URLRequestMethod.POST; 
  10.     jpgURLRequest.data = jpgStream
  11.     navigateToURL(jpgURLRequest, "_blank"); 
  12. var video:Video = new Video; 
  13. addChild(video); 
  14. video.attachCamera(Camera.getCamera()); 
  15. var btn:Sprite = new Sprite; 
  16. btn.graphics.beginFill(0,1); 
  17. btn.graphics.drawRoundRect(0,0,100,25,10); 
  18. btn.x = 110
  19. btn.y = 250
  20. btn.buttonMode = true
  21. btn.addEventListener(MouseEvent.CLICK, clickHandler); 
  22. addChild(btn); 

两个类文件BitString.as, JPGEncoder.as,下载后注意大小写,此wp不知道咋整的,把偶上传时的大写都改成小写了。

  1. <?php 
  2. if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) { 
  3.     // CuPlayer.com酷播 get bytearray 
  4.     $im = $GLOBALS["HTTP_RAW_POST_DATA"]; 
  5.     // CuPlayer.com酷播 add headers for download dialog-box 
  6.     header('Content-Type: image/jpeg'); 
  7.     header("Content-Disposition: attachment; filename=".$_GET['name']); 
  8.     echo $im; 
  9. }  else echo 'An error occured.'; 
  10. ?> 

 

ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室