記念撮影アプリ

簡単にカメラを使った記念撮影アプリを作ってみました。
こんな感じ。

ソースはこちら

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" title="Home" creationComplete="init(event)" xmlns:local="*" xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
        <![CDATA[
            import com.adobe.images.JPGEncoder;
            import mx.events.FlexEvent;
            import mx.graphics.codec.JPEGEncoder;
            protected function init(event:FlexEvent):void
            {
                var cam:Camera = Camera.getCamera();
                cam.setMode(640,480,10);
                var vd:Video =  new Video(cam.width,cam.height);
                vd.rotation = 90;
                vd.x = 480;
                vd.attachCamera(cam);
                myUI.addChild(vd);
            }
            protected function onClick(e:Event):void{
                var bmd:BitmapData = new BitmapData(480,640);
                bmd.draw(myGroup);
                var jpge:JPGEncoder = new JPGEncoder(80);
                var img:ByteArray = jpge.encode(bmd);
                //var file:File = File.desktopDirectory.resolvePath("webcam.jpg");
                var file:File = File.documentsDirectory.resolvePath("webcam.jpg");
                var stream:FileStream = new FileStream();
                stream.open(file, FileMode.WRITE);
                stream.writeBytes(img);
                stream.close();
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Group id="myGroup" width="480" height="640">
        <mx:UIComponent id="myUI"/>
        <s:Image x="174" y="107" source="@Embed('../assets/image.png')"/>
    </s:Group>
    <s:Button label="ハイチーズ!" click="onClick(event)" bottom="20" horizontalCenter="0"/>
</s:View>