jsp在线拍照
本帖最后由 xieruilin 于 2010-07-27 20:04:58 编辑 jsp如何调用flash开发在线拍照???谁有例子????跪求。。。。
[解决办法]
printf@126.com;406768212@qq.com; 邮件已发,根据提供的那个例子改了一下,可以实现拍照保存jpg图片至本地,可能需要装flashplayer 10环境 附代码:
flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="388" height="222" creationComplete="initApp()">
<mx:Style>
Alert{font-size:12px;}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.graphics.codec.JPEGEncoder;
import mx.events.CloseEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private static const DEFAULT_CAMERA_WIDTH:Number = 160; //摄像头显示宽度
private static const DEFAULT_CAMERA_HEIGHT:Number = 120; //摄像头显示高度
private var m_camera:Camera; //定义一个摄像头
private var m_localVideo:Video; //定义一个本地视频
private var m_pictureBitmapData:BitmapData //定义视频截图
[Bindable]
private var m_pictureData:String;
[Bindable]
private var m_pictureBitmap:Bitmap;
private function initApp():void
{
/* t_btn_Shooting.enabled = false;
t_ban_Save.enabled = false; */
initCamera();
}
private function initCamera():void
{
m_camera = Camera.getCamera();
if(m_camera != null)
{
m_camera.addEventListener(StatusEvent.STATUS,__onCameraStatusHandler);
m_camera.setMode(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT,30);
m_localVideo = new Video();
m_localVideo.width = DEFAULT_CAMERA_WIDTH;
m_localVideo.height = DEFAULT_CAMERA_HEIGHT;
m_localVideo.attachCamera(m_camera);
t_vd_Video.addChild(m_localVideo);
} else
{
Alert.show("没有找到摄像头,是否重新查找。","提示:",Alert.OK
[解决办法]
Alert.NO,this,__InitCamera);
return;
}
}
//拍照按钮事件,进行视频截图
private function SnapshotPicture():void
{
m_pictureBitmapData = new BitmapData(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT);
m_pictureBitmapData.draw(t_vd_Video,new Matrix());
m_pictureBitmap = new Bitmap(m_pictureBitmapData);
t_img_Picture.addChild(m_pictureBitmap);
t_panel_Picture.visible = true;
t_ban_Save.enabled = true;
}
//保存按钮事件,保存视频截图
private var file:FileReference = new FileReference();
private function SavePicture():void
{
var jpg:JPEGEncoder = new JPEGEncoder();
var ba:ByteArray = jpg.encode(m_pictureBitmapData);
file.save(ba,'1.jpg');
/*
var copyfile:FileReference = file;
var request: URLRequest = new URLRequest();
request.url="upphotoservlet";
request.method = "post";
copyfile.upload(request); // 将拍摄的照片上传至服务器 */
}
//检测摄像头权限事件
private function __onCameraStatusHandler(event:StatusEvent):void
{
if(!m_camera.muted)
{
t_btn_Shooting.enabled = true;
}
else
{
Alert.show("无法链接到活动摄像头,是否重新检测。","提示:",Alert.OK
[解决办法]
Alert.NO,this,__InitCamera);
}
m_camera.removeEventListener(StatusEvent.STATUS,__onCameraStatusHandler);
}
//当摄像头不存在,或连接不正常时重新获取
private function __InitCamera(event:CloseEvent):void
{
if(event.detail == Alert.OK)
{
initApp();
}
}
//WebService保存图片成功事件
private function __onSavePictureResult(event:ResultEvent):void
{
//trace(event.result);
if(event.result.toString() == "保存成功")
{
Alert.show(event.result.toString(),"提示",Alert.OK,this,__onAlertCloseHandler);
}
else
{
Alert.show(event.result.toString(),"提示",Alert.OK);
}
}
//保存图片成功后的弹出窗口确认事件
private function __onAlertCloseHandler(event:CloseEvent):void
{
if(event.detail == Alert.OK)
{
//trace("转向页面");
}
}
]]>
</mx:Script>
<mx:Panel x="10" y="10" width="180" height="200" layout="absolute" title="视频拍照" fontSize="12">
<mx:VideoDisplay id="t_vd_Video" width="160" height="120"/>
<mx:ControlBar horizontalAlign="right">
<mx:Button id="t_btn_Shooting" label="拍照" click="SnapshotPicture()"/>
</mx:ControlBar>
</mx:Panel>
<mx:Panel id="t_panel_Picture" x="198" y="10" width="180" height="200" layout="absolute" title="拍照图片" fontSize="12" visible="false">
<mx:Image id="t_img_Picture" x="0" y="0" width="160" height="120"/>
<mx:ControlBar horizontalAlign="right">
<mx:Button id="t_ban_Save" label="保存" click="SavePicture()" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="cameraflex" width="388" height="222"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="cameraflex.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="cameraflex.swf" quality="high" bgcolor="#869ca7"
width="388" height="222" name="cameraflex" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</body>
</html>