用flash as3截取攝像頭圖片信息交由php保存[flash+php保存圖片]

 

前段時間做了一個類似的應用,現將源代碼公佈。(請自行配置php和gd2庫)
Flash as3:(放到幀上,可自行修改移至相關class)

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

兩個類文件BitString.as, JPGEncoder.as,下載後注意大小寫,此wp不知道咋整的,把偶上傳時的大寫都改成小寫了。
php:

  1. <?php
  2. if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
  3.     // get bytearray
  4.     $im = $GLOBALS["HTTP_RAW_POST_DATA"];
  5.     // 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. ?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章