Flex Client Code:
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"
Xmlns:s= "Library://ns.adobe.com/flex/spark"
xmlns:mx= "Library://ns.adobe.com/flex/mx" minwidth= "955" minheight= "creationcomplete=" application1_ Creationcompletehandler (event) ">
<fx:Script>
<! [cdata[
Import Mx.controls.Alert;
Import mx.core.UIComponent;
Import mx.events.FlexEvent;
Import Mx.graphics.codec.JPEGEncoder;
Import mx.rpc.events.FaultEvent;
Import mx.rpc.events.ResultEvent;
Import Mx.utils.UIDUtil;
protected function Application1_creationcompletehandler (event:flexevent): void
{
Initcamera (Videodis);
}
Initializes the camera control and adds it to the Videodisplay
Public Function Initcamera (videodis:uicomponent): void
{
var Mycamera:camera = Camera.getcamera ();//Get Client Camera
Mycamera.setmode (500,500,30);
var myvideo:video = new Video (500,500);
Myvideo.attachcamera (Mycamera);//Get the video stream of the camera
Videodis.addchild (Myvideo);
}
Convert a visual uicomponent component to a picture
Public Function Uitobitmap (source:uicomponent,target:uicomponent): void
{
var width:int = source.width;
var height:int = source.height;
var bitmapdata:bitmapdata =new BitmapData (width,height);
Bitmapdata.draw (Source,new Matrix ());
var bitmap:bitmap=new bitmap (BitmapData);
var uic:uicomponent = new UIComponent ();
Uic.addchild (bitmap);
Target.addchild (UIC);
}
To save a visual uicomponent component as a local picture
Public Function Uisaveasimg (imgid:uicomponent): void
{
var width:int = imgid.width;
var height:int = imgid.height;
var bitmapdata:bitmapdata =new BitmapData (width,height);
Bitmapdata.draw (Imgid);
var Bytearr:bytearray = bitmapdata.getpixels (new Rectangle (0,0,width,height));
var bytearr123:bytearray =new Jpegencoder (). Encodebytearray (Bytearr,width,height);
var filerefer:filereference = new Filereference ();
Filerefer.save (Bytearr123,uidutil.createuid () + ". png");
Filerefer.addeventlistener (Event.complete,function completehandler (): void{
Alert.show ("Save local Success");
});
}
Upload photos to the server
protected function Uploadimg (imgid:uicomponent): void
{
var width:int = imgid.width;
var height:int = imgid.height;
var bitmapdata:bitmapdata =new BitmapData (width,height);
Bitmapdata.draw (Imgid);
var Bytearr:bytearray = bitmapdata.getpixels (new Rectangle (0,0,width,height));
var bytearr123:bytearray =new Jpegencoder (). Encodebytearray (Bytearr,width,height);
Webservice.uploadfile (byteArr123, "123.png");
}
protected function Webservice_faulthandler (event:faultevent): void
{
Alert.show (Event.fault.toString ());
}
protected function Webservice_successhandler (event:resultevent): void
{
Alert.show (Event.result.toString ());
}
]]>
</fx:Script>
<fx:Declarations>
<!--place non-visual elements (such as services, value objects) here-->
<s:webservice id= "WebService" wsdl= "Http://10.19.1.48/upImg/Service1.asmx?" WSDL "fault=" Webservice_faulthandler (event) >
<s:operation name= "UploadFile" result= "Webservice_successhandler (event)" ></s:operation>
</s:WebService>
</fx:Declarations>
<s:videodisplay id= "Videodis" width= "height=" "click=" Uitobitmap (videodis,t_img_picture), UItoBitmap ( videodis,content) "tooltip=" click on photo ></s:VideoDisplay>
<mx:datechooser id= "mydate" x= "y=" 508 "click=" Uitobitmap (mydate,t_img_picture), Uitobitmap (myDate,content) " tooltip= "Click to Photograph"/>
<mx:image id= "t_img_picture" x= "522" y= "0" width= "height=" "click=" uisaveasimg (t_img_picture) "toolTip=" Click Save Local "/>
<mx:canvas id= "Content" x= "" "y=" "Width=" height= "(" ")," "" "(" click= ")" Uisaveasimg "tooltip=" "," click Save Local "> </mx:Canvas>
<s:button x= "305" y= "537" label= "upload" width= "130" height= "the" click= "Uploadimg" (t_img_picture) "/>"
</s:Application>
WebService Code:
Copy Code code as follows:
<summary>
Uploading files to a remote server
</summary>
<param name= "filebytes" > File Flow </param>
<param name= "filename" > FileName </param>
<returns> string </returns>
[WebMethod (Description = "Upload file to remote server.")]
public string UploadFile (byte[] filebytes, string fileName)
{
Try
{
MemoryStream MemoryStream = new MemoryStream (filebytes); 1. Define and instantiate a memory stream to hold the byte array that is submitted.
FileStream fileupload = new FileStream (Server.MapPath (".") + "\" + FileName, FileMode.Create); 2. Define the actual file object and save the uploaded file.
Memorystream.writeto (FileUpload); 3. Write the data in the memory stream to the physical file
Memorystream.close ();
Fileupload.close ();
FileUpload = null;
MemoryStream = null;
Return "file has been successfully uploaded to the server";
}
catch (Exception ex)
{
Return ex. message;
}
}