Click here to Skip to main content
15,312,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have written a code in my action script of flash builder to interact with my web cam.I am able to take the pic .but can not able to read the image in my aspx page?So I am unblae to save it.Can amybody please tell me ,How to save the Image in my system through asp.net??My code is as follows..


//In the .mxml page

<s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="#unknown">
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="getCam();">

<fx:declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->

<mx:fade id="flashFX" duration="550" xmlns:mx="#unknown">

<s:parallel id="discardPhoto">
<s:children>
<mx:zoom xmlns:mx="#unknown">
duration="350"
zoomWidthFrom="1.0"
zoomWidthTo="0.01"
zoomHeightFrom="1.0"
zoomHeightTo="0.01"
target="{previewBox}"/>
<mx:fade duration="350">



<s:vgroup horizontalcenter="0" verticalcenter="0">
<s:group id="videoArea">
<mx:videodisplay id="theCam" width="400" height="300" xmlns:mx="#unknown">
<s:group id="previewBox" visible="false" hideeffect="{discardPhoto}">
<mx:image id="preview" width="100%" height="100%" xmlns:mx="#unknown">
<s:bordercontainer>
id="flashLight"
width="100%"
height="100%"
hideEffect="{flashFX}"
backgroundColor="white"
backgroundAlpha="0.8"/>

<s:bordercontainer>
bottom="0"
width="100%"
backgroundColor="black"
backgroundAlpha="0.4"
borderColor="black"
height="55">
<s:button>
id="trigger"
horizontalCenter="0"
verticalCenter="0"
label="Take a picture!"
height="35"
chromeColor="#33abe9"
color="#ffffff"
click="takePicture();" />


<s:hgroup verticalalign="middle" horizontalalign="right" width="100%">
<mx:linkbutton label="Cancel" xmlns:mx="#unknown">
<s:button>
id="savePic"
label="Save picture"
height="30"
enabled="false"
toolTip="Make it your profile image!"
click="savePicture();"
/>


<fx:script source="CamSetup.as">


//Code in the CamSetup.as page
import flash.display.BitmapData;
import flash.net.sendToURL;
import flash.net.drm.LoadVoucherSetting;

import mx.controls.Alert;
import mx.graphics.codec.JPEGEncoder;
import mx.rpc.http.HTTPService;
import mx.utils.Base64Encoder;

private var bm:BitmapData;



//this method is used to detect webcam and attach it to webpage
private function getCam():void
{
if (Camera.getCamera())
{
// assign the user's default camera to a variable
var camera:Camera = Camera.getCamera();

// set the camera quality to be the highest as possible
camera.setQuality(110, 100);

// set the width, height, frames per second
camera.setMode(theCam.width, theCam.height, 30);

// attach the camera to our "theCam" VideoDisplay
theCam.attachCamera(camera);
}

else
{
trace("Camera Not Found");
}

}

public function takePicture():void {

//if we are not previewing any picture, we'll take one :)
if (!previewBox.visible) {

//create a BitmapData variable called picture that has theCam's size
var picture:BitmapData = new BitmapData(theCam.width, theCam.height);

//the BitmapData draws our theCam
picture.draw(theCam);

//Our preview's source is a new Bitmap made of picture's BitmapData
preview.source = new Bitmap(picture);

//stores this BitmapData into another BitmapData (outside this function)
bm = picture;

//makes the previewBox visible, so we can see our picture
previewBox.visible = true;

//displays the flashLight
flashLight.visible = true;

//makes the flashLight go way
flashLight.visible = false;

//change our trigger label, so the user will be able to try again
trigger.label = "Take another picture...";

//enables the savePic button
savePic.enabled = true;

//changes the color of the button
trigger.setStyle('chromeColor', '#ff0000');

}

//if we are previewing a picture...
else {

//makes the previewBox invisible
previewBox.visible = false;

//changes the label
trigger.label = 'Take a picture!';

//disables the savePic button
savePic.enabled = false;

//changes the color of the button
trigger.setStyle('chromeColor', '#33abe9');

}

}

public function savePicture():void {

//change the savePic button label so the user knows as soon as possible
//that we are saving his picture
savePic.label = "Saving..."

//disables the button so the user don't click it twice
savePic.enabled = false;

//the trigger button displays a nice message
trigger.label = "That's a nice picture :)"

//disables the "trigger" button, now is too late to take another picture!
trigger.enabled = false;


//creates a new JPEGEncoder called "je"
//sets the quality to 100 (maximum)
var je:JPEGEncoder = new JPEGEncoder(100);

//creates a new ByteArray called "ba"
//JPEGEnconder encodes our "bm" Bitmap data: our "picture"
var ba:ByteArray = je.encode(bm);
//this ByteArray is now an encoded JPEG

//creates a new Base64Encoder called "be"
var be:Base64Encoder = new Base64Encoder();

//encodes our "ba" ByteArray (wich is our JPEG encoded picture) with base64Encoder
be.encodeBytes(ba);

//Now we have our "encodedData" string to send to the server
var encodedData:String = be.flush();

//CODE FOR WEBCAM TESTING .ASPX PAGE STARTS HERE

var service:HTTPService = new HTTPService();
service.url="http://localhost:2324/WebCamTesting.aspx";
//service.url="http://localhost:2324/Handler1.ashx";

service.method = "POST";
service.showBusyCursor=true;

service.send({content: encodedData});

//Code in my .aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class WebCamTesting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var p = Request.Params["content"];
}
}
}
Posted
Updated 4-Feb-15 22:50pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900