用flash as3截取摄像头图片信息交由php保存[flash+php保存图片]
用flash as3截取摄像头图片信息交由php保存[flash+php保存图片] 收藏
前段时间做了一个类似的应用,现将源代码公布。(请自行配置php和gd2库)
Flash as3:(放到帧上,可自行修改移至相关class)
function clickHandler(e:MouseEvent):void
{
var bitmapdata:BitmapData = new BitmapData(video.width, video.height);
bitmapdata.draw(video);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);//图片质量
var jpgStream:ByteArray = jpgEncoder.encode(bitmapdata);
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest ("http://localhost/jpg_encoder_download.php?name=camera.jpg"); //此web url请自行修改
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
}
var video:Video = new Video;
addChild(video);
video.attachCamera(Camera.getCamera());
var btn:Sprite = new Sprite;
btn.graphics.beginFill(0,1);
btn.graphics.drawRoundRect(0,0,100,25,10);
btn.x = 110;
btn.y = 250;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(btn);
两个类文件BitString.as, JPGEncoder.as,下载后注意大小写,此wp不知道咋整的,把偶上传时的大写都改成小写了。
php:
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
// get bytearray
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $im;
} else echo 'An error occured.';
?>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ppanyong/archive/2008/11/10/3268455.aspx