使用flex+fluorineFx+webservices(C#)
其中注意的是.net环境与flex环境的结合,fluorineFx的引用,端口的配置。代码是没多少难度的,网上有很多资料。
可以去我的资源里下代码:http://download.csdn.net/source/569396
.net flex(FluorineFX) 项目建立参考:
1.唐勇blog:[翻译]配置FluorineFX环境
http://hi.baidu.com/ishowing/blog/item/68cf1330a572359da8018e36.html
2. Baijinwen blog:vs2008+flex builder 3+FluorineFx項目搭建
http://blog.csdn.net/Baijinwen/archive/2008/03/20/2199587.aspx
不过这个我参照的时候有flex建立professional都会出现一个错误:C:/Program Files/Adobe/Flex Builder 3/sdks/3.0.0
/frameworks/locale/en_US-services"../../WEB-INF/flex/services-config.xml"-context-root/WebSite1'
有人说用vs2008没事,试过也是同样的。不知道是什么原因(对和个太生疏了)。解决的办法(只是解决了,应该不是用这个方法):把services-config.xml复制到你的flex mxml源文件的文件夹。
flex 和webservices代码:
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.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 static const DEFAULT_WEBSERVICE_URL:String = "http://localhost:6666/WebSite1/WebService.asmx?WSDL"; //WebService地址
- private var m_camera:Camera; //定义一个摄像头
- private var m_localVideo:Video; //定义一个本地视频
- private var m_pictureBitmapData:BitmapData //定义视频截图
- [Bindable]
- private var m_pictureData:String;
- 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());
- 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 < DEFAULT_CAMERA_WIDTH; i++)
- {
- for(var j:int = 0; j < DEFAULT_CAMERA_HEIGHT; j++)
- {
- if(m_pictureData.length > 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("转向页面");
- }
- }
- ]]>
- </mx:Script>
- <mx:WebService id="t_ws_SavePicture" showBusyCursor="true" wsdl="{DEFAULT_WEBSERVICE_URL}" useProxy="false" result="__onSavePictureResult(event)" fault="__onSavePictureFault(event)">
- <mx:operation name="SavePicture">
- <mx:request>
- <pic_width>{DEFAULT_CAMERA_WIDTH}</pic_width>
- <pic_height>{DEFAULT_CAMERA_HEIGHT}</pic_height>
- <bitmap_data>{m_pictureData}</bitmap_data>
- </mx:request>
- </mx:operation>
- </mx:WebService>
- <mx:Panel x="10" y="10" width="180" height="200" layout="absolute" title="视频拍照" >
- <mx:VideoDisplay id="t_vd_Video" width="160" height="120"/>
- <mx:ControlBar >
- <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="拍照图片" visible="false">
- <mx:Image id="t_img_Picture" x="0" y="0" width="160" height="120"/>
- <mx:ControlBar>
- <mx:Button id="t_ban_Save" label="保存" click="SavePicture()" />
- </mx:ControlBar>
- </mx:Panel>
- </mx:Application>
webservices:
- using System;
- using System.Collections;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.Drawing;
- using System.IO;
- /// <summary>
- ///WebService 的摘要说明
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
- // [System.Web.Script.Services.ScriptService]
- public class WebService : System.Web.Services.WebService
- {
- public WebService()
- {
- //如果使用设计的组件,请取消注释以下行
- //InitializeComponent();
- }
- [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 < pic_height; j++)
- {
- uint pic_argb = (uint)long.Parse(m_tempPics[i * pic_height + j]);
- int pic_a = (int)(pic_argb >> 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, System.Drawing.Imaging.ImageFormat.Png);
- return "保存成功";
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
- }
aspx:
- <div>
- <object id="paizhao" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
- height="368" width="440" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" >
- <param name="_cx" value="11642"/>
- <param name="_cy" value="9737"/>
- <param name="FlashVars" value=""/>
- <param name="Movie" value="Flex/pz.swf"/>
- <param name="Src" value="Flex/pz.swf"/>
- <param name="WMode" value="Window"/>
- <param name="Play" value="-1"/>
- <param name="Loop" value="-1"/>
- <param name="Quality" value="High"/>
- <param name="SAlign" value=""/>
- <param name="Menu" value="-1"/>
- <param name="Base" value=""/>
- <param name="AllowScriptAccess" value=""/>
- <param name="Scale" value="ShowAll"/>
- <param name="DeviceFont" value="0"/>
- <param name="EmbedMovie" value="0"/>
- <param name="BGColor" value=""/>
- <param name="SWRemote" value=""/>
- <param name="MovieData" value=""/>
- <param name="SeamlessTabbing" value="1"/>
- <param name="Profile" value="0"/>
- <param name="ProfileAddress" value=""/>
- <param name="ProfilePort" value="0"/>
- <script type="text/javascript "> if (navegiator . mimeTypes && navigator . mimeTypes["application/x-shockwave-flash"] { document . write('<embed src="Flex/pz.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
- type="application/x-shockwave-flash" width="220" height="184" name="paizhao"> </embed>')}
- </script>
- </object>
- </div>