Fluorine .NET Flash Remoting Gateway

Sending webcam image to the server

This sample converts the camera image to BitmapData. The BitmapData is converted to a ByteArray using the PNG Encoder in AS3. Then the ByteArray is sent to the .NET backend.

Client side

//Connect the camera

var video:Video;
var camera:Camera = Camera.getCamera();
if(camera != null)
{
     video = new Video(camera.width , camera.height );
     video.attachCamera(camera);
     //var comp: UIComponent = new UIComponent();
     //comp.addChild(video);
     //myPanel.addChild(comp);
}

//Send to the server

var gatewayURL:String = "http://127.0.0.1/FluorineWeb/Gateway.aspx";
var gateway_conn:RemotingConnection = new RemotingConnection();
gateway_conn.connect(gatewayURL);
var responder:Responder = new Responder(onSendImageResult, onSendImageStatus);

var bitmapData:BitmapData = new BitmapData(video.width, video.height);
bitmapData.draw(video);
var pngData:ByteArray = PNGEnc.encode(bitmapData);

gateway_conn.call("FluorineWeb.FlexService1.SendImage", responder, pngData );

Server side

using com.TheSilentGroup.Fluorine.AMF3;
...

public void SendImage(ByteArray byteArray)
{
     uint length = byteArray.Length;
     byte[] bytes = new byte[length];
     byteArray.ReadBytes( bytes, 0, length);
     MemoryStream ms = new MemoryStream(bytes);

     Image img = Bitmap.FromStream(ms);
     Bitmap bmp = new Bitmap(img);

     //To save the image to a file
     MemoryStream tempStream = new MemoryStream();
     bmp.Save(tempStream,System.Drawing.Imaging.ImageFormat.Png);
     FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("test.png"), FileMode.Create);
     tempStream.WriteTo(fs);
     tempStream.Close();
     fs.Close();
}