Discuz!NT的上传头像功能(Silverlight)

  Silverlight版与之前的Flash版在功能上没什么差别,但由于这个是在.Net平台上开发,完成可以根据自己的需要来进行修改。源码在 webcam.codeplex.com 可以下载,但某些装了 WINDOWS 2003 的机器在保存图片时会出错。

  Discuz!NT的上传头像功能(Silverlight)
  Discuz!NT的上传头像功能(Silverlight)

  页面的服务器端代码跟Flash版的一样,就不贴代码了,但客户端要加上

代码
   
     
< div id ="avatarSilverlight" style ="clear: both; display: none; width: 520px; height: 300px;" >
< script type ="text/javascript" src ="<%=Localhost %>/silverlight/Avatar/Silverlight.js" reload ="1" ></ script >
< div id ="silverlightControlHost" style ="width: 520px; height: 300px;" >
< object id ="avatarUpload" data ="data:application/x-silverlight-2," type ="application/x-silverlight-2"
width
="520px" height ="300px" >
< param name ="source" value ="<%=Localhost %>/silverlight/Avatar/ClientBin/WebCam.xap" />
< param name ="onError" value ="onSilverlightError" />
< param name ="background" value ="white" />
< param name ="minRuntimeVersion" value ="4.0.50401.0" />
< param name ="onLoad" value ="onLoad" />
< param name ="autoUpgrade" value ="true" />
< param name ="initParams" value ="authToken=ADAGiwINbm8=,savePath=/images/upload/avatars/{0}/{0}_" />
< a href ="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style ="text-decoration: none"
target
="_blank" >
< img src ="<%=Localhost %>/silverlight/Avatar/avatar.jpg" alt ="安装微软Silverlight控件,即刻使用银光头像"
style
="border-style: none" />
</ a >
</ object >
</ div >
< script type ="text/javascript" >
function onLoad(plugin, userContext, sender) {
$(
" avatarUpload " ).content.JavaScriptObject.CloseAvatar = updateavatar; // 注册js方法以便silverlight调用
}
</ script >
</ div >

其中  <param name="source" value="<%=Localhost %>/silverlight/Avatar/ClientBin/WebCam.xap" />这句为Silverlight文件的路径。如果服务器不支持xap文件,可以文件后缀改为html。
<param name="initParams" value="authToken=ADAGiwINbm8=,savePath=/images/upload/avatars/{0}/{0}_" /> 这句为向Silverlight 设置参数,savePath为保存图片的路径,{0}的用户的ID。servicePath 为 WebService文件的路径不改变

 

代码下载

你可能感兴趣的:(silverlight)