user3100533
user3100533

Reputation: 505

Webcam shows mirror image using action script

Using Flash CS5.5 and action script 3 I have made a small application for image capturing through web cam and integrated it in php page working perfect also save image. But problem is it shows MIRROR image on screen means if I move my right hand on screen it shows left hand. My query is how can I correct this setting. Here is the code -

package take_picture_fla
{
    import com.adobe.images.*;
    import flash.display.*;
    import flash.events.*;
    import flash.media.*;
    import flash.net.*;
    import flash.ui.*;
    import flash.utils.*;

    dynamic public class MainTimeline extends MovieClip
    {
        public var capture_mc:MovieClip;
        public var bitmap:Bitmap;
        public var rightClickMenu:ContextMenu;
        public var snd:Sound;
        public var video:Video;
        public var bitmapData:BitmapData;
        public var warn:MovieClip;
        public var save_mc:MovieClip;
        public var bandwidth:int;
        public var copyright:ContextMenuItem;
        public var cam:Camera;
        public var quality:int;

        public function MainTimeline()
        {
            addFrameScript(0, frame1);
            return;
        }// end function

        public function onSaveJPG(event:Event) : void
        {
            var myEncoder:JPGEncoder;
            var byteArray:ByteArray;
            var header:URLRequestHeader;
            var saveJPG:URLRequest;
            var urlLoader:URLLoader;
            var sendComplete:Function;
            var e:* = event;
            sendComplete = function (event:Event) : void
            {
                warn.visible = true;
                addChild(warn);
                warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
                warn.buttonMode = true;
                return;
            }// end function
            ;
            myEncoder = new JPGEncoder(100);
            byteArray = myEncoder.encode(bitmapData);
            header = new URLRequestHeader("Content-type", "application/octet-stream");
            saveJPG = new URLRequest("save.php");
            saveJPG.requestHeaders.push(header);
            saveJPG.method = URLRequestMethod.POST;
            saveJPG.data = byteArray;
            urlLoader = new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, sendComplete);
            urlLoader.load(saveJPG);
            return;
        }// end function

        public function warnDown(event:MouseEvent) : void
        {
            navigateToURL(new URLRequest("images/"), "_blank");
            warn.visible = false;
            return;
        }// end function

        function frame1()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            rightClickMenu = new ContextMenu();
            copyright = new ContextMenuItem("Developed By www.webinfopedia.com Go to Application");
            copyright.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, myLink);
            copyright.separatorBefore = false;
            rightClickMenu.hideBuiltInItems();
            rightClickMenu.customItems.push(copyright);
            this.contextMenu = rightClickMenu;
            snd = new camerasound();
            bandwidth = 0;
            quality = 100;
            cam = Camera.getCamera();
            cam.setQuality(bandwidth, quality);
            cam.setMode(320, 240, 30, false);
            video = new Video();
            video.attachCamera(cam);
            video.x = 20;
            video.y = 20;
            addChild(video);
            bitmapData = new BitmapData(video.width, video.height);
            bitmap = new Bitmap(bitmapData);
            bitmap.x = 360;
            bitmap.y = 20;
            addChild(bitmap);
            capture_mc.buttonMode = true;
            capture_mc.addEventListener(MouseEvent.CLICK, captureImage);
            save_mc.alpha = 0.5;
            warn.visible = false;
            return;
        }// end function

        public function captureImage(event:MouseEvent) : void
        {
            snd.play();
            bitmapData.draw(video);
            save_mc.buttonMode = true;
            save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG);
            save_mc.alpha = 1;
            return;
        }// end function

        public function myLink(event:Event)
        {
            navigateToURL(new URLRequest("http://www.webinfopedia.com/export-database-data-to-excel-in-php.html"), "_blank");
            return;
        }// end function

    }
}

Upvotes: 0

Views: 1717

Answers (2)

Bill Turner
Bill Turner

Reputation: 1010

You should check your camera's settings at the system level - it is possible that the device driver is set to mirror the image.

Upvotes: 0

Fygo
Fygo

Reputation: 4665

You can just use video.scaleX = -1; to mirror the image.

Upvotes: 1

Related Questions