Flex2中的代码片段,用于实现拍照功能.
FLEX实现抓取图像,通过JPEGEncoder转换成ByteArray,返回.
剩下的工作简单了,获取图像保存而 已
php 实现
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![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try {
17
loader.load(req);
18
}
19![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch (error:Error) {
20
trace('unable to load request');
21
}
22
23![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
function saveImageListeners(dispatcher:IEventDispatcher):void {
24
dispatcher.addEventListener(Event.COMPLETE, onComplete);
25
}
26
27![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
FLEX实现抓取图像,通过JPEGEncoder转换成ByteArray,返回.
剩下的工作简单了,获取图像保存而 已
php 实现
1
$fp
=
fopen
(
'
php.jpg
'
,
'
wb
'
);
2
fwrite
(
$fp
,
$GLOBALS
[
'
HTTP_RAW_POST_DATA
'
]);
3
fclose
(
$fp
);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
C# 实现
1
System.Drawing.Image img
=
System.Drawing.Image.FromStream(Request.InputStream);
2
img.Save(
@"
D:\path\asp.jpg
"
);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)