




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Flex采集摄像头照片-增加裁剪功能由于系统中用到的flex采集照片需要裁减功能,就把前几天搜到的Flex源码进行了修改,实现了裁减功能,不过做的比较简单,呵呵!Flex部分: Alertfont-size:12px; !CDATA 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 = 320; private static const DEFAULT_CAMERA_HEIGHT:Number = 240; private static const DEFAULT_WEBSERVICE_URL:String = http:/localhost:50338/WebSite1/WebService.asmx?WSDL; /WebService地址 private var m_camera:Camera; /定义一个摄像头 private var m_localVideo:Video; /定义一个本地视频 private var m_pictureBitmapData:BitmapData /定义视频截图 public static var MoveMouseblnMove:Boolean = false; public static var blnMove:Boolean = false; Bindable private var m_pictureData:String; private function initApp():void t_btn_Shooting.enabled = false; t_ban_Save.enabled = false; initMouseEvent(); 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 var r: Rectangle = new Rectangle(this.t_cv_canvasResize.x, this.t_cv_canvasResize.y, this.t_cv_canvasResize.width, this.t_cv_canvasResize.height); var m: Matrix = new Matrix(1, 0, 0, 1, -Math.ceil(r.x), -Math.ceil(r.y); m_pictureBitmapData = new BitmapData(Math.floor(r.width), Math.floor(r.height); m_pictureBitmapData.draw(t_vd_Video,m); var m_pictureBitmap:Bitmap = new Bitmap(m_pictureBitmapData); t_img_Picture.addChild(m_pictureBitmap); t_panel_Picture.visible = true; t_ban_Save.enabled = true; /保存按钮事件,保存视频截图 /通过WebService保存 private function SavePicture():void m_pictureData = ; for(var i:int = 0; i this.t_cv_canvasResize.width; i+) for(var j:int = 0; j 0) m_pictureData += , + m_pictureBitmapData.getPixel32(i,j).toString(); else m_pictureData = m_pictureBitmapData.getPixel32(i,j).toString(); t_ws_SavePicture.SavePicture.send(); /检测摄像头权限事件 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); /连接WebService失败事件 private function _onSavePictureFault(event:FaultEvent):void /Alert.show(event.fault.toString(),提示,Alert.OK); Alert.show(连接WebService失败。,提示,Alert.OK); /保存图片成功后的弹出窗口确认事件 private function _onAlertCloseHandler(event:CloseEvent):void if(event.detail = Alert.OK) /trace(转向页面); /添加鼠标事件监听 public function initMouseEvent() : void this.t_cv_canvasResize.addEventListener(MouseEvent.MOUSE_DOWN, this.MoveMouseDownHandler); this.t_cv_canvasResize.addEventListener(MouseEvent.MOUSE_UP, this.MoveMouseUpHandler); this.t_cv_canvasParent.addEventListener(MouseEvent.ROLL_OUT, this.ParentMouseOverHandler); this.t_cv_canvasParent.addEventListener(MouseEvent.MOUSE_UP, this.ParentMouseOverHandler); return; / end function public function MoveMouseDownHandler(event:MouseEvent) : void MoveMouseblnMove = true; var _loc_2:Rectangle = new Rectangle(); _loc_2.width = this.t_vd_Video.width - this.t_cv_canvasResize.width; _loc_2.height = this.t_vd_Video.height - this.t_cv_canvasResize.height; this.t_cv_canvasResize.startDrag(false, _loc_2); return; / end function public function MoveMouseUpHandler(event:MouseEvent) : void this.t_cv_canvasResize.stopDrag(); MoveMouseblnMove = true; return; / end function public function ParentMouseOverHandler(event:MouseEvent) : void this.t_cv_canvasResize.stopDrag(); blnMove = false; MoveMouseblnMove = false; return; / end function this.t_cv_canvasResize.width this.t_cv_canvasResize.height m_pictureData WebService部分: WebMethod public string SavePicture(int pic_width, int pic_height, string bitmap_data) try Bitmap m_pic = new Bitmap(pic_width, pic_height); string m_tempPics = bitmap_data.Split(,); for (int i = 0; i pic_width; i+) for (int j = 0; j 24 & 0xFF); int pic_r = (int)(pic_argb 16 & 0xFF); int pic_g = (int)(pic_argb 8 & 0xFF); int pic_b = (int)(pic_argb & 0xFF); m_pic.SetPixel(i, j, Color.FromArgb(pic_a, pic_r, pic_g, pic_b); string filePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + Photo; /判断路径是否存在,若不存在则创建路径 DirectoryInfo upDir = new DirectoryInfo(filePath); if (!upDir.Exists) upDir.Create(); /生成随机文件名 Random objRand = new Random(); DateTime date = DateTime.Now; /生成随机文件名 string saveName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + Convert.ToString(objRand.Next(99) * 97 + 100); string fileName = saveName + .jpg; m_pic.Save(filePath + fileName, ImageFormat.Jpeg); return 保存成功; catch (Exception ex) return ex.Message; flex摄像头拍照 java上传到数据库public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html;charset=UTF-8); response.setHeader(Pragma, No-cache); response.setHeader(Cache-Control, no-cache); response.setDateHeader(Expires, 0); String bitmap_data = request.getParameter(bitmap_data); int width = commons.getRequestInt(request.getParameter(width),0); int height = commons.getRequestInt(request.getParameter(height),0); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); try int w = width; int h = height; int pixels = new intw * h; String m_tempPics = bitmap_data.split(,); for (int x = 0; x w; x+) for (int y = 0; y 24 & 0xFF); int r = (int) (pic_argb 16 & 0xFF); /右移16位 ,取后8位; int g = (int) (pic_argb 8 & 0xFF); int b = (int) (pic_argb & 0xFF); pixelsy * w + x = new Color(r, g, b, a).getRGB(); img.setRGB(0, 0, w, h, pixels, 0, w); img.flush(); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ImageIO.write(img, jpg, bao); byte data = bao.toByteArray(); Personimage user = new Personimage(); user.setFileContent(data); PersonimageDAO hm = new PersonimageDAO(); hm.save(user); PersonrelationDAO prm = new PersonrelationDAO(); Personrelation pr = prm.findById(new Long(personRelationId); pr.setPersonimageid(user.getId(); pr.setImageflag(1); prm.update(pr); str.append(保存成功); catch (Exception e) e.printStackTrace(); str.append(保存失败); response.setContentType(text/xml); response.getWriter().write(str.toString(); flex视频录制import mx.events.SliderEvent;import mx.events.VideoEvent;import mx.collections.ArrayCollection;import mx.rpc.events.ResultEvent;import mx.core.UIComponent;import flash.events.StatusEvent;import flash.events.SecurityErrorEvent;import flash.media.Camera;import flash.media.Microphone;import .NetConnection;/由于fms使用的是amf0而flex3中的as3默认使用的是amf3.所以要让flex使用AFM0NetConnection.defaultObjectEncoding = .ObjectEncoding.AMF0;/视频服务端地址private var _videoServerURL:String = “rtmp:/07/test”;private var _camera:Camera; /定义一个摄像头private var _mic:Microphone; /定义一个麦克风private var _localVideo:Video; /定义一个本地视频private var _netConnection:NetConnection;private var _outStream:NetStream; /定义一个输出流private var _inStream:NetStream; /定义一个输入流private var isplaying:Boolean=false; /定义是否正在播放标记private var isrecing:Boolean = false; /定义是否正在录制标记private var ispauseing:Boolean = false; /定义是否正在暂停标记private var _duration:Number; /定义视频持续时间private var playPosition:Number; /定义播放进度位置private var soundPosition:Number; /定义声音大小控制条的位置private function playinit():voidt_hs_control.enabled=false;t_btn_play.enabled = false;t_btn_stop.enabled = false;t_btn_rec.enabled = false;t_btn_save.enabled = false;t_lbl_rec.visible = false;initCameraAndMic(); /初始化摄像头/初始化摄像头/判断是否存在摄像头和访问权限private function initCameraAndMic():void_camera = Camera.getCamera();if(_camera != null)_camera.addEventListener(StatusEvent.STATUS,_onStatusHandler);_camera.setMode(320,420,30);/t_flv_video.attachCamera(_camera);_localVideo = new Video();_localVideo.width = 320;_localVideo.height = 240;_localVideo.attachCamera(_camera);t_flv_video.addChild(_localVideo);_mic = Microphone.getMicrophone();if(_mic != null)/未添加侦听麦克连接状态/设置本自本地的麦克风的音频传送到本地系统扬声器/*_mic.setUseEchoSuppression(true);_mic.setLoopBack(true);*/_mic.setSilenceLevel(0,-1); /设置麦克风保持活动状态并持续接收集音频数据_mic.gain = 80; /设置麦克风声音大小/开始录制视频/检测网络连接状态private function beginOrShowRecVideo():void_netConnection = new NetConnection();_netConnection.addEventListener(NetStatusEvent.NET_STATUS,_onNetStatusHandler);_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,_onSecurityErrorHandler);_netConnection.connect(_videoServerURL);/录制视频,向服务器传送视频及音频流private function beginRecConnectStream():voidif(_localVideo != null)_localVideo.clear();t_flv_video.removeChild(_localVideo);_localVideo = new Video();_localVideo.width = 320;_localVideo.height = 240;_localVideo.attachCamera(_camera);t_flv_video.addChild(_localVideo);_outStream = new NetStream(_netConnection);_outStream.attachCamera(_camera);_outStream.attachAudio(_mic);_outStream.publish(”testVideo”,”record”);/播放视频private function showRecConnectStream():void_inStream = new NetStream(_netConnection);_inStream.addEventListener(NetStatusEvent.NET_STATUS,_onNetStatusHandler);_inStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,_onStreamErrorHandler);/定义onMetaData,获取视频相关数据var customClient:Object = new Object();customClient.onMetaData = function(metadata:Object):void_duration = metadata.duration; /获取视频持续时间t_hs_control.maximum = _duration; /设置播放进度条最大值_inStream.client = customClient;/删除原_localVideo,便于在录制和播放视频之间切换_localVideo.clear();t_flv_video.removeChild(_localVideo);_localVideo = new Video();_localVideo.width = 320;_localVideo.height = 240;_localVideo.attachNetStream(_inStream);_inStream.play(”testVideo”);t_flv_video.addChild(_localVideo);/播放按钮点击后事件:播放视频,同时分析是否播放来调整BUTTON上的标签,显示为播放或者暂停;/并监听播放器private function flvplay(event:Event):voidt_hs_control.enabled=true;t_btn_stop.enabled = true;t_btn_rec.enabled = false;if(!isplaying)isplaying = true;beginOrShowRecVideo();else_inStream.togglePause(); /自动在停止和播放之间切换if(isplaying)if(ispauseing)t_btn_play.label=”播放”else t_btn_play.label=”暂停”ispauseing = !ispauseing;addEventListener(Event.ENTER_FRAME,_onEnterFrame);/停止按钮和视频播放完毕/重设一些值变量、按钮enabled值等private function resetSomeParam():void_inStream.close();t_btn_play.label = “播放”;t_lbl_playtime.text = “0:00 / “+ formatTimes(_duration);t_hs_control.value = 0;isplaying = false;ispauseing = false;t_hs_control.enabled=false;t_btn_rec.enabled = true;t_btn_stop.enabled = false;/停止播放按钮点击事件:停止视频,同时调整相关BUTTON上的标签private function flvStop(event:Event):voidresetSomeParam();removeEventListener(Event.ENTER_FRAME,_onEnterFrame);/拉动进度条private function thumbPress(event:SliderEvent):void_inStream.togglePause();removeEventListener(Event.ENTER_FRAME,_onEnterFrame);/进度条改变后,得到的值赋予PLAYPOSITION;private f
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 日系风格毕业论文
- 个人理财投资实战手册
- 基础设计考研试题及答案
- 机电系模具毕业论文
- 新材料研发应用研究合作协议
- 2024班级管理工作总结范本(4篇)
- 2025玉米采购的合同范本
- 商业技术保密协议模板
- 工业生产与装备操作作业指导书
- 2024年代缴公积金协议
- 阿尔茨海默患者的护理
- 连锁药店质量管理制度
- 农产品销售公司岗位职责及团队架构
- 【仲量联行】2024年重庆商业地产市场报告
- 解读化妆品监督管理条例
- 2024年重庆沙坪坝区社会选拔社区专职工作者后备人选笔试真题
- 《经济学的基本原理》课件
- 货物运输合作协议范本
- 美团骑手2025年度骑手权益保障与法律法规遵守合同4篇
- 2025年中州水务控股有限公司招聘笔试参考题库含答案解析
- 彩钢瓦屋面施工材料选用方案
评论
0/150
提交评论