Skip to main content
Participant
May 26, 2010
Question

capturing images frm camera in web application with Action scripts and Flash

  • May 26, 2010
  • 1 reply
  • 568 views

hi all,


I am new to this scripting part,basically i m working as a web developer on Microsoft Technologies.

We have requirement of web conferencing in our application.

Before that we also need capturing images directly frm camera and stroed into our application.


I searched a lot then find that it is possible with flash media and action scripting.

with that you access client system.


I have never done coding in AS3 before...So donot knw how to go about?

Even dnt knw how add it later in our web application.

I need a start.........


Can anyone please suggest me.......


Thanks & Regards,


navi

This topic has been closed for replies.

1 reply

Participant
May 26, 2010

Hi, see the sample below...

Sorry but i cant find "Add file" button. ;-(

package {
imports ......................
    public class TestVideo extends Sprite
{
       private var cam   :Camera;
        private var _frame  :VirtualFrame;
  private var _video  :Video;
 
        public function TestVideo()         // most part of code from help
  {
   stage.scaleMode = StageScaleMode.NO_SCALE;
   stage.align = StageAlign.TOP_LEFT;
  
            cam = Camera.getCamera();
   cam.setMode(stage.stageWidth - 20, stage.stageHeight - 20, 30);
   cam.setQuality(cam.bandwidth, 100);
            if (!cam) {
                trace("No camera is installed.");
               
            } else if (cam.muted) {
trace("muted");

            }else {

                connectCamera();
            }
        }

        private function connectCamera():void
  {
            _video = new Video(cam.width, cam.height);
            _video.x = 10;
   _video.y = 10;
   _video.attachCamera(cam);
  
   _frame = new VirtualFrame();
   _frame.dragRect = new Rectangle(_video.x, _video.y, _video.width, _video.height);
   _frame.addEventListener(VirtualFrameEvent.SELECT, onScreenCropHandler);
  
            addChild(_video);   
   addChild(_frame);

        }
 
  private function onScreenCropHandler(e:VirtualFrameEvent):void
  {
   var tempRect:Rectangle = e.selectedArea.clone();

    tempRect.x = 0;

    tempRect.y = 0;
   var tempMatrix:Matrix = new Matrix();

    tempMatrix.tx -= e.selectedArea.x - _video.x;

    tempMatrix.ty -= e.selectedArea.y - _video.y;
   var tempBMD:BitmapData = new BitmapData(tempRect.width, tempRect.height);

    tempBMD.draw(_video, tempMatrix, null, null, tempRect);

// uncomment to save to localfile
/*   var encoder:JPEGEncoder = new JPEGEncoder(100);

   var ba:ByteArray = encoder.encode(tempBMD);
   var saveFile :FileReference = new FileReference;
   try    { saveFile.save(ba, "from_camera.jpg"); }

   catch (e:Error) { trace(e.message); }*/
   stage.addChild(new Bitmap(tempBMD, "auto", true));
   _frame.block = true;

   removeChild(_video);

  }

}

ohhh...i post it, i crop most part of code..

navs123Author
Participant
May 31, 2010

Thanks 4 replying back..

i just copy paste your code.

But i m getting error below:

**Error**  Line 1: Syntax error.
     package {

**Error**  Line 2: Attribute used outside class.
         public class TestVideo extends Sprite

**Error**  Line 3: The class or interface 'Sprite' could not be loaded.
     {

**Error**  Line 5: The class or interface 'VirtualFrame' could not be loaded

Actually namespaces or assemblies for these classes are not loaded I dnt knw why????

any suggestion

Participant
May 31, 2010

This is only part of code, not a ready sample. Ask in ICQ 298403791 and i can send full source.